// 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"

	customTypes "github.com/CiscoDevNet/terraform-provider-aci/v2/internal/custom_types"
	"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-log/tflog"
)

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

func NewQosCustomPolDataSource() datasource.DataSource {
	return &QosCustomPolDataSource{}
}

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

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

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

		Attributes: map[string]schema.Attribute{
			"id": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: "The distinguished name (DN) of the Custom QoS Policy object.",
			},
			"parent_dn": schema.StringAttribute{
				Required:            true,
				MarkdownDescription: "The distinguished name (DN) of the parent object.",
			},
			"annotation": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `The annotation of the Custom QoS Policy object.`,
			},
			"description": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `The description of the Custom QoS Policy object.`,
			},
			"name": schema.StringAttribute{
				Required:            true,
				MarkdownDescription: `The name of the Custom QoS Policy object.`,
			},
			"name_alias": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `The name alias of the Custom QoS 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.`,
			},
			"dot1p_classifiers": schema.SetNestedAttribute{
				MarkdownDescription: `The class level for dot1P to prioritize the map.`,
				Computed:            true,
				NestedObject: schema.NestedAttributeObject{
					Attributes: map[string]schema.Attribute{
						"annotation": schema.StringAttribute{
							Computed:            true,
							MarkdownDescription: `The annotation of the Dot1p Classifier object.`,
						},
						"description": schema.StringAttribute{
							Computed:            true,
							MarkdownDescription: `The description of the Dot1p Classifier object.`,
						},
						"from": schema.StringAttribute{
							CustomType:          customTypes.QosDot1PClassFromStringType{},
							Computed:            true,
							MarkdownDescription: `The Dot1p priority range starting value.`,
						},
						"name": schema.StringAttribute{
							Computed:            true,
							MarkdownDescription: `The name of the Dot1p Classifier object.`,
						},
						"name_alias": schema.StringAttribute{
							Computed:            true,
							MarkdownDescription: `The name alias of the Dot1p Classifier object.`,
						},
						"priority": schema.StringAttribute{
							CustomType:          customTypes.QosDot1PClassPrioStringType{},
							Computed:            true,
							MarkdownDescription: `The Quality of Service (QoS) priority class ID. QoS refers to the capability of a network to provide better service to selected network traffic over various technologies. The primary goal of QoS is to provide priority including dedicated bandwidth, controlled jitter and latency (required by some real-time and interactive traffic), and improved loss characteristics. You can configure the bandwidth of each QoS level using QoS profiles.`,
						},
						"target": schema.StringAttribute{
							CustomType:          customTypes.QosDot1PClassTargetStringType{},
							Computed:            true,
							MarkdownDescription: `The target of the Dot1p Classifier object. This Fabric only supports DSCP mutation, Dot1P mutation is not supported.`,
						},
						"target_cos": schema.StringAttribute{
							CustomType:          customTypes.QosDot1PClassTargetCosStringType{},
							Computed:            true,
							MarkdownDescription: `The target Class of Service (CoS) to be driven based on the range of DSCP input values coming into the fabric.`,
						},
						"to": schema.StringAttribute{
							CustomType:          customTypes.QosDot1PClassToStringType{},
							Computed:            true,
							MarkdownDescription: `The Dot1p priority range ending value.`,
						},
						"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.`,
									},
								},
							},
						},
					},
				},
			},
			"dscp_to_priority_maps": schema.SetNestedAttribute{
				MarkdownDescription: `The class level for DSCP to prioritize the map.`,
				Computed:            true,
				NestedObject: schema.NestedAttributeObject{
					Attributes: map[string]schema.Attribute{
						"annotation": schema.StringAttribute{
							Computed:            true,
							MarkdownDescription: `The annotation of the DSCP to Priority Map object.`,
						},
						"description": schema.StringAttribute{
							Computed:            true,
							MarkdownDescription: `The description of the DSCP to Priority Map object.`,
						},
						"from": schema.StringAttribute{
							CustomType:          customTypes.QosDscpClassFromStringType{},
							Computed:            true,
							MarkdownDescription: `The DSCP range starting value.`,
						},
						"name": schema.StringAttribute{
							Computed:            true,
							MarkdownDescription: `The name of the DSCP to Priority Map object.`,
						},
						"name_alias": schema.StringAttribute{
							Computed:            true,
							MarkdownDescription: `The name alias of the DSCP to Priority Map object.`,
						},
						"priority": schema.StringAttribute{
							CustomType:          customTypes.QosDscpClassPrioStringType{},
							Computed:            true,
							MarkdownDescription: `The Quality of Service (QoS) priority class ID. QoS refers to the capability of a network to provide better service to selected network traffic over various technologies. The primary goal of QoS is to provide priority including dedicated bandwidth, controlled jitter and latency (required by some real-time and interactive traffic), and improved loss characteristics. You can configure the bandwidth of each QoS level using QoS profiles.`,
						},
						"target": schema.StringAttribute{
							CustomType:          customTypes.QosDscpClassTargetStringType{},
							Computed:            true,
							MarkdownDescription: `The target of the DSCP to Priority Map object. This Fabric only supports DSCP mutation, Dot1P mutation is not supported.`,
						},
						"target_cos": schema.StringAttribute{
							CustomType:          customTypes.QosDscpClassTargetCosStringType{},
							Computed:            true,
							MarkdownDescription: `Target COS to be driven based on the range of input values of DSCP coming into the fabric.`,
						},
						"to": schema.StringAttribute{
							CustomType:          customTypes.QosDscpClassToStringType{},
							Computed:            true,
							MarkdownDescription: `The DSCP range ending value.`,
						},
						"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_custom_qos_policy")
}

func (d *QosCustomPolDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
	tflog.Debug(ctx, "Start configure of datasource: aci_custom_qos_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_custom_qos_policy")
}

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

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

	if resp.Diagnostics.HasError() {
		return
	}

	setQosCustomPolId(ctx, data)

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

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

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

	if data.Id.IsNull() {
		resp.Diagnostics.AddError(
			"Failed to read aci_custom_qos_policy data source",
			fmt.Sprintf("The aci_custom_qos_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_custom_qos_policy with id '%s'", data.Id.ValueString()))
}
