package provider

import (
	"context"
	"fmt"
	"github.com/UPDATE_PATH_TO_MODELS/models"
	"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-framework/types/basetypes"
	"{{sdk_client_path}}"
	"{{resource_path}}"
)

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

func New{{resource_name}}DataSource() datasource.DataSource {
	return &{{resource_name}}DataSource{}
}

// {{resource_name}}DataSource is the data source implementation.
type {{resource_name}}DataSource struct {
	client *Client.{{resource_name}}
}

// {{resource_name}}DataSourceModel describes the data model.
type {{resource_name}}DataSourceModel struct {
	{% for var in struct_vars -%}
	{{var}}
    {% endfor %}
}

// Metadata returns the data source type name.
func (r *{{resource_name}}DataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
	resp.TypeName = req.ProviderTypeName + "_{{resource_name}}"
}

// Schema defines the schema for the data source.
func (r *{{resource_name}}DataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
	resp.Schema = schema.Schema{
		MarkdownDescription: "{{resource_name}} DataSource",

		Attributes: map[string]schema.Attribute{
			{% for var in schema_method -%}
			{{var}},
			{% endfor %}
		},
	}
}

func (r *{{resource_name}}DataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
	// Prevent panic if the provider has not been configured.
	if req.ProviderData == nil {
		return
	}

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

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

		return
	}

	r.client = client
}

{% include "read_method.j2" %}

{% include "data_source_res.j2" %}
