// Code generated by "gen/generator.go"; DO NOT EDIT.
// In order to regenerate this file execute `go generate` from the repository root.
// More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md).

package provider

import (
	"context"
	"fmt"

	"github.com/ciscoecosystem/aci-go-client/v2/client"

	"github.com/hashicorp/terraform-plugin-framework/datasource"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/types"
	"github.com/hashicorp/terraform-plugin-log/tflog"
)

// Ensure provider defined types fully satisfy framework interfaces.
var _ datasource.DataSource = &CommPolDataSource{}

func NewCommPolDataSource() datasource.DataSource {
	return &CommPolDataSource{}
}

// CommPolDataSource defines the data source implementation.
type CommPolDataSource struct {
	client *client.Client
}

func (d *CommPolDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
	tflog.Debug(ctx, "Start metadata of datasource: aci_management_access_policy")
	resp.TypeName = req.ProviderTypeName + "_management_access_policy"
	tflog.Debug(ctx, "End metadata of datasource: aci_management_access_policy")
}

func (d *CommPolDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
	tflog.Debug(ctx, "Start schema of datasource: aci_management_access_policy")
	resp.Schema = schema.Schema{
		// This description is used by the documentation generator and the language server.
		MarkdownDescription: "The management_access_policy datasource for the 'commPol' class",

		Attributes: map[string]schema.Attribute{
			"id": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: "The distinguished name (DN) of the Management Access Policy object.",
			},
			"annotation": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `The annotation of the Management Access Policy object.`,
			},
			"description": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `The description of the Management Access Policy object.`,
			},
			"name": schema.StringAttribute{
				Required:            true,
				MarkdownDescription: `The name of the Management Access Policy object.`,
			},
			"name_alias": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `The name alias of the Management Access Policy object.`,
			},
			"owner_key": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `The key for enabling clients to own their data for entity correlation.`,
			},
			"owner_tag": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `A tag for enabling clients to add their own data. For example, to indicate who created this object.`,
			},
			"strict_security_on_apic_oob_subnet": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Removes implicit access permissions from any APIC out-of-band (OOB) subnet IP address.`,
			},
			"http_service": schema.SingleNestedAttribute{
				MarkdownDescription: `HTTP`,
				Computed:            true,
				Attributes: map[string]schema.Attribute{
					"allow_credentials": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `Determines if credentials are allowed in HTTP responses.`,
					},
					"allow_origins": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `Determines which origins can access the resource. For example, inputting http://127.0.0.1:8000 would allow access from a source device with that IP address and port.`,
					},
					"admin_state": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The administrative state of the HTTP Service.`,
					},
					"annotation": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The annotation of the HTTP Service object.`,
					},
					"cli_only_mode": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `Determines if CLI-only mode is enabled.`,
					},
					"description": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The description of the HTTP Service object.`,
					},
					"global_throttle_rate": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The maximum amount of API calls allowed per unit time.`,
					},
					"global_throttle_state": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The throttle state for all clients without specific identifier in their headers.`,
					},
					"global_throttle_unit": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The unit of measurement for rate limiting.`,
					},
					"max_request_status_count": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The maximum number of request status objects to keep.`,
					},
					"name": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The name of the HTTP Service object.`,
					},
					"name_alias": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The name alias of the HTTP Service object.`,
					},
					"node_exporter": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The node exporter service status.`,
					},
					"port": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The port used by the HTTP communication service.`,
					},
					"redirect_state": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The state of HTTP communication service.`,
					},
					"server_header": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `Determines if the server header is included in responses.`,
					},
					"login_throttle_rate": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The maximum login/refresh allowed per second.`,
					},
					"login_throttle_state": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The state of login and refresh throttling.`,
					},
					"visore_access": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `Grants permissions for accessing the Visore tool, also known as Object Store Browser, in Cisco ACI.`,
					},
					"annotations": schema.SetNestedAttribute{
						MarkdownDescription: ``,
						Computed:            true,
						NestedObject: schema.NestedAttributeObject{
							Attributes: map[string]schema.Attribute{
								"key": schema.StringAttribute{
									Computed:            true,
									MarkdownDescription: `The key used to uniquely identify this configuration object.`,
								},
								"value": schema.StringAttribute{
									Computed:            true,
									MarkdownDescription: `The value of the property.`,
								},
							},
						},
					},
					"tags": schema.SetNestedAttribute{
						MarkdownDescription: ``,
						Computed:            true,
						NestedObject: schema.NestedAttributeObject{
							Attributes: map[string]schema.Attribute{
								"key": schema.StringAttribute{
									Computed:            true,
									MarkdownDescription: `The key used to uniquely identify this configuration object.`,
								},
								"value": schema.StringAttribute{
									Computed:            true,
									MarkdownDescription: `The value of the property.`,
								},
							},
						},
					},
				},
			},
			"http_ssl_configuration": schema.SingleNestedAttribute{
				MarkdownDescription: `HTTPS`,
				Computed:            true,
				Attributes: map[string]schema.Attribute{
					"allow_credentials": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `Determines if credentials are allowed in HTTPS responses.`,
					},
					"allow_origins": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `Determines which origins can access the resource. For example, inputting http://127.0.0.1:8000 would allow access from a source device with that IP address and port.`,
					},
					"admin_state": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The administrative state of the HTTPS Service.`,
					},
					"annotation": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The annotation of the HTTPS Service object.`,
					},
					"cli_only_mode": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `Determines if CLI-only mode is enabled.`,
					},
					"client_certificate_authentication_state": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The authentication state of the client certificate.`,
					},
					"description": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The description of the HTTPS Service object.`,
					},
					"dh_parameter": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `Determines the settings for Diffie-Hellman (DH) parameters.`,
					},
					"global_throttle_rate": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The maximum amount of API calls allowed per unit time.`,
					},
					"global_throttle_state": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The throttle state for all clients without specific identifier in their headers.`,
					},
					"global_throttle_unit": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The unit of measurement for rate limiting specified with the 'global_throttle_rate' attribute.`,
					},
					"max_request_status_count": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The maximum number of request status objects to keep.`,
					},
					"name": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The name of the HTTPS Service object.`,
					},
					"name_alias": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The name alias of the HTTPS Service object.`,
					},
					"node_exporter": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The node exporter service status.`,
					},
					"port": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The port used by the HTTPS communication service.`,
					},
					"referer": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `Allowed HTTP referers.`,
					},
					"server_header": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `Determines if the server header is included in responses.`,
					},
					"ssl_protocols": schema.SetAttribute{
						Computed:            true,
						MarkdownDescription: `The SSL protocols allowed by HTTPS communication service.`,
						ElementType:         types.StringType,
					},
					"login_throttle_rate": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The maximum login/refresh allowed per second.`,
					},
					"login_throttle_state": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The state of login and refresh throttling.`,
					},
					"visore_access": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `Grants permissions for accessing the Visore tool, also known as Object Store Browser, in Cisco ACI.`,
					},
					"certificate_authority": schema.SingleNestedAttribute{
						MarkdownDescription: ``,
						Computed:            true,
						Attributes: map[string]schema.Attribute{
							"annotation": schema.StringAttribute{
								Computed:            true,
								MarkdownDescription: `The annotation of the Certificate Authority object.`,
							},
							"target_dn": schema.StringAttribute{
								Computed:            true,
								MarkdownDescription: `The distinguished name of the target.`,
							},
							"annotations": schema.SetNestedAttribute{
								MarkdownDescription: ``,
								Computed:            true,
								NestedObject: schema.NestedAttributeObject{
									Attributes: map[string]schema.Attribute{
										"key": schema.StringAttribute{
											Computed:            true,
											MarkdownDescription: `The key used to uniquely identify this configuration object.`,
										},
										"value": schema.StringAttribute{
											Computed:            true,
											MarkdownDescription: `The value of the property.`,
										},
									},
								},
							},
							"tags": schema.SetNestedAttribute{
								MarkdownDescription: ``,
								Computed:            true,
								NestedObject: schema.NestedAttributeObject{
									Attributes: map[string]schema.Attribute{
										"key": schema.StringAttribute{
											Computed:            true,
											MarkdownDescription: `The key used to uniquely identify this configuration object.`,
										},
										"value": schema.StringAttribute{
											Computed:            true,
											MarkdownDescription: `The value of the property.`,
										},
									},
								},
							},
						},
					},
					"key_ring": schema.SingleNestedAttribute{
						MarkdownDescription: `A source relation to a key ring.`,
						Computed:            true,
						Attributes: map[string]schema.Attribute{
							"annotation": schema.StringAttribute{
								Computed:            true,
								MarkdownDescription: `The annotation of the Key Ring object.`,
							},
							"key_ring_name": schema.StringAttribute{
								Computed:            true,
								MarkdownDescription: `The HTTP connection key ring. Each PKI device holds a pair of asymmetric Rivest-Shamir-Adleman (RSA) or Elliptic Curve Cryptography (ECC) encryption keys, one kept private and one made public, stored in an internal key ring.`,
							},
							"annotations": schema.SetNestedAttribute{
								MarkdownDescription: ``,
								Computed:            true,
								NestedObject: schema.NestedAttributeObject{
									Attributes: map[string]schema.Attribute{
										"key": schema.StringAttribute{
											Computed:            true,
											MarkdownDescription: `The key used to uniquely identify this configuration object.`,
										},
										"value": schema.StringAttribute{
											Computed:            true,
											MarkdownDescription: `The value of the property.`,
										},
									},
								},
							},
							"tags": schema.SetNestedAttribute{
								MarkdownDescription: ``,
								Computed:            true,
								NestedObject: schema.NestedAttributeObject{
									Attributes: map[string]schema.Attribute{
										"key": schema.StringAttribute{
											Computed:            true,
											MarkdownDescription: `The key used to uniquely identify this configuration object.`,
										},
										"value": schema.StringAttribute{
											Computed:            true,
											MarkdownDescription: `The value of the property.`,
										},
									},
								},
							},
						},
					},
					"annotations": schema.SetNestedAttribute{
						MarkdownDescription: ``,
						Computed:            true,
						NestedObject: schema.NestedAttributeObject{
							Attributes: map[string]schema.Attribute{
								"key": schema.StringAttribute{
									Computed:            true,
									MarkdownDescription: `The key used to uniquely identify this configuration object.`,
								},
								"value": schema.StringAttribute{
									Computed:            true,
									MarkdownDescription: `The value of the property.`,
								},
							},
						},
					},
					"tags": schema.SetNestedAttribute{
						MarkdownDescription: ``,
						Computed:            true,
						NestedObject: schema.NestedAttributeObject{
							Attributes: map[string]schema.Attribute{
								"key": schema.StringAttribute{
									Computed:            true,
									MarkdownDescription: `The key used to uniquely identify this configuration object.`,
								},
								"value": schema.StringAttribute{
									Computed:            true,
									MarkdownDescription: `The value of the property.`,
								},
							},
						},
					},
				},
			},
			"ssh_access_via_web": schema.SingleNestedAttribute{
				MarkdownDescription: ``,
				Computed:            true,
				Attributes: map[string]schema.Attribute{
					"admin_state": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The administrative state of the SSH access via WEB object.`,
					},
					"annotation": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The annotation of the SSH access via WEB object.`,
					},
					"description": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The description of the SSH access via WEB object.`,
					},
					"name": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The name of the SSH access via WEB object.`,
					},
					"name_alias": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The name alias of the SSH access via WEB object.`,
					},
					"annotations": schema.SetNestedAttribute{
						MarkdownDescription: ``,
						Computed:            true,
						NestedObject: schema.NestedAttributeObject{
							Attributes: map[string]schema.Attribute{
								"key": schema.StringAttribute{
									Computed:            true,
									MarkdownDescription: `The key used to uniquely identify this configuration object.`,
								},
								"value": schema.StringAttribute{
									Computed:            true,
									MarkdownDescription: `The value of the property.`,
								},
							},
						},
					},
					"tags": schema.SetNestedAttribute{
						MarkdownDescription: ``,
						Computed:            true,
						NestedObject: schema.NestedAttributeObject{
							Attributes: map[string]schema.Attribute{
								"key": schema.StringAttribute{
									Computed:            true,
									MarkdownDescription: `The key used to uniquely identify this configuration object.`,
								},
								"value": schema.StringAttribute{
									Computed:            true,
									MarkdownDescription: `The value of the property.`,
								},
							},
						},
					},
				},
			},
			"ssh_service": schema.SingleNestedAttribute{
				MarkdownDescription: `Object that encompasses properties related to Secure Shell access to the APIC, namely admin-state (default=enabled) and port(default=22).`,
				Computed:            true,
				Attributes: map[string]schema.Attribute{
					"admin_state": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The administrative state of the SSH Service object.`,
					},
					"annotation": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The annotation of the SSH Service object.`,
					},
					"description": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The description of the SSH Service object.`,
					},
					"host_key_algorithms": schema.SetAttribute{
						Computed:            true,
						MarkdownDescription: `The supported algorithms for the host key.`,
						ElementType:         types.StringType,
					},
					"kex_algorithms": schema.SetAttribute{
						Computed:            true,
						MarkdownDescription: `The supported algorithms for key exchange.`,
						ElementType:         types.StringType,
					},
					"name": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The name of the SSH Service object.`,
					},
					"name_alias": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The name alias of the SSH Service object.`,
					},
					"password_authentication_state": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `Determines the state of password-based authentication to control administrator access to the management interfaces of the ACI fabric.`,
					},
					"port": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The port used by the SSH service.`,
					},
					"ssh_ciphers": schema.SetAttribute{
						Computed:            true,
						MarkdownDescription: `The ciphers supported by the SSH service.`,
						ElementType:         types.StringType,
					},
					"ssh_macs": schema.SetAttribute{
						Computed:            true,
						MarkdownDescription: `The message authentication codes (MACs) supported by the SSH service.`,
						ElementType:         types.StringType,
					},
					"annotations": schema.SetNestedAttribute{
						MarkdownDescription: ``,
						Computed:            true,
						NestedObject: schema.NestedAttributeObject{
							Attributes: map[string]schema.Attribute{
								"key": schema.StringAttribute{
									Computed:            true,
									MarkdownDescription: `The key used to uniquely identify this configuration object.`,
								},
								"value": schema.StringAttribute{
									Computed:            true,
									MarkdownDescription: `The value of the property.`,
								},
							},
						},
					},
					"tags": schema.SetNestedAttribute{
						MarkdownDescription: ``,
						Computed:            true,
						NestedObject: schema.NestedAttributeObject{
							Attributes: map[string]schema.Attribute{
								"key": schema.StringAttribute{
									Computed:            true,
									MarkdownDescription: `The key used to uniquely identify this configuration object.`,
								},
								"value": schema.StringAttribute{
									Computed:            true,
									MarkdownDescription: `The value of the property.`,
								},
							},
						},
					},
				},
			},
			"telnet_service": schema.SingleNestedAttribute{
				MarkdownDescription: `Telnet`,
				Computed:            true,
				Attributes: map[string]schema.Attribute{
					"admin_state": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The administrative state of the Telnet Service object.`,
					},
					"annotation": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The annotation of the Telnet Service object.`,
					},
					"description": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The description of the Telnet Service object.`,
					},
					"name": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The name of the Telnet Service object.`,
					},
					"name_alias": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The name alias of the Telnet Service object.`,
					},
					"port": schema.StringAttribute{
						Computed:            true,
						MarkdownDescription: `The port used by the Telnet service.`,
					},
					"annotations": schema.SetNestedAttribute{
						MarkdownDescription: ``,
						Computed:            true,
						NestedObject: schema.NestedAttributeObject{
							Attributes: map[string]schema.Attribute{
								"key": schema.StringAttribute{
									Computed:            true,
									MarkdownDescription: `The key used to uniquely identify this configuration object.`,
								},
								"value": schema.StringAttribute{
									Computed:            true,
									MarkdownDescription: `The value of the property.`,
								},
							},
						},
					},
					"tags": schema.SetNestedAttribute{
						MarkdownDescription: ``,
						Computed:            true,
						NestedObject: schema.NestedAttributeObject{
							Attributes: map[string]schema.Attribute{
								"key": schema.StringAttribute{
									Computed:            true,
									MarkdownDescription: `The key used to uniquely identify this configuration object.`,
								},
								"value": schema.StringAttribute{
									Computed:            true,
									MarkdownDescription: `The value of the property.`,
								},
							},
						},
					},
				},
			},
			"annotations": schema.SetNestedAttribute{
				MarkdownDescription: ``,
				Computed:            true,
				NestedObject: schema.NestedAttributeObject{
					Attributes: map[string]schema.Attribute{
						"key": schema.StringAttribute{
							Computed:            true,
							MarkdownDescription: `The key used to uniquely identify this configuration object.`,
						},
						"value": schema.StringAttribute{
							Computed:            true,
							MarkdownDescription: `The value of the property.`,
						},
					},
				},
			},
			"tags": schema.SetNestedAttribute{
				MarkdownDescription: ``,
				Computed:            true,
				NestedObject: schema.NestedAttributeObject{
					Attributes: map[string]schema.Attribute{
						"key": schema.StringAttribute{
							Computed:            true,
							MarkdownDescription: `The key used to uniquely identify this configuration object.`,
						},
						"value": schema.StringAttribute{
							Computed:            true,
							MarkdownDescription: `The value of the property.`,
						},
					},
				},
			},
		},
	}
	tflog.Debug(ctx, "End schema of datasource: aci_management_access_policy")
}

func (d *CommPolDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
	tflog.Debug(ctx, "Start configure of datasource: aci_management_access_policy")
	// Prevent panic if the provider has not been configured.
	if req.ProviderData == nil {
		return
	}

	client, ok := req.ProviderData.(*client.Client)

	if !ok {
		resp.Diagnostics.AddError(
			"Unexpected Data Source Configure Type",
			fmt.Sprintf("Expected *client.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
		)

		return
	}

	d.client = client
	tflog.Debug(ctx, "End configure of datasource: aci_management_access_policy")
}

func (d *CommPolDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
	tflog.Debug(ctx, "Start read of datasource: aci_management_access_policy")
	var data *CommPolResourceModel

	// Read Terraform configuration data into the model
	resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)

	if resp.Diagnostics.HasError() {
		return
	}

	setCommPolId(ctx, data)

	// Create a copy of the Id for when not found during getAndSetCommPolAttributes
	cachedId := data.Id.ValueString()

	tflog.Debug(ctx, fmt.Sprintf("Read of datasource aci_management_access_policy with id '%s'", data.Id.ValueString()))

	getAndSetCommPolAttributes(ctx, &resp.Diagnostics, d.client, data)

	if data.Id.IsNull() {
		resp.Diagnostics.AddError(
			"Failed to read aci_management_access_policy data source",
			fmt.Sprintf("The aci_management_access_policy data source with id '%s' has not been found", cachedId),
		)
		return
	}

	// Save data into Terraform state
	resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
	tflog.Debug(ctx, fmt.Sprintf("End read of datasource aci_management_access_policy with id '%s'", data.Id.ValueString()))
}
