// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package schema_validation_schemas

import (
	"context"

	"github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"
	"github.com/hashicorp/terraform-plugin-framework-validators/datasourcevalidator"
	"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
	"github.com/hashicorp/terraform-plugin-framework/datasource"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/path"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

var _ datasource.DataSourceWithConfigValidators = (*SchemaValidationSchemasDataSource)(nil)

func DataSourceSchema(ctx context.Context) schema.Schema {
	return schema.Schema{
		Attributes: map[string]schema.Attribute{
			"id": schema.StringAttribute{
				Description: "UUID.",
				Computed:    true,
			},
			"schema_id": schema.StringAttribute{
				Description: "UUID.",
				Computed:    true,
				Optional:    true,
			},
			"zone_id": schema.StringAttribute{
				Description: "Identifier.",
				Required:    true,
			},
			"omit_source": schema.BoolAttribute{
				Description: "Omit the source-files of schemas and only retrieve their meta-data.",
				Computed:    true,
				Optional:    true,
			},
			"created_at": schema.StringAttribute{
				Computed:   true,
				CustomType: timetypes.RFC3339Type{},
			},
			"kind": schema.StringAttribute{
				Description: "The kind of the schema\nAvailable values: \"openapi_v3\".",
				Computed:    true,
				Validators: []validator.String{
					stringvalidator.OneOfCaseInsensitive("openapi_v3"),
				},
			},
			"name": schema.StringAttribute{
				Description: "A human-readable name for the schema",
				Computed:    true,
			},
			"source": schema.StringAttribute{
				Description: "The raw schema, e.g., the OpenAPI schema, either as JSON or YAML",
				Computed:    true,
			},
			"validation_enabled": schema.BoolAttribute{
				Description: "An indicator if this schema is enabled",
				Computed:    true,
			},
			"filter": schema.SingleNestedAttribute{
				Optional: true,
				Attributes: map[string]schema.Attribute{
					"omit_source": schema.BoolAttribute{
						Description: "Omit the source-files of schemas and only retrieve their meta-data.",
						Computed:    true,
						Optional:    true,
					},
					"validation_enabled": schema.BoolAttribute{
						Description: "Filter for enabled schemas",
						Optional:    true,
					},
				},
			},
		},
	}
}

func (d *SchemaValidationSchemasDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
	resp.Schema = DataSourceSchema(ctx)
}

func (d *SchemaValidationSchemasDataSource) ConfigValidators(_ context.Context) []datasource.ConfigValidator {
	return []datasource.ConfigValidator{
		datasourcevalidator.ExactlyOneOf(path.MatchRoot("schema_id"), path.MatchRoot("filter")),
	}
}
