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

package list_item

import (
	"context"

	"github.com/cloudflare/terraform-provider-cloudflare/internal/customfield"
	"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
	"github.com/hashicorp/terraform-plugin-framework/datasource"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

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

func DataSourceSchema(ctx context.Context) schema.Schema {
	return schema.Schema{
		Attributes: map[string]schema.Attribute{
			"account_id": schema.StringAttribute{
				Description: "The Account ID for this resource.",
				Required:    true,
			},
			"list_id": schema.StringAttribute{
				Description: "The unique ID of the list.",
				Required:    true,
			},
			"item_id": schema.StringAttribute{
				Description: "Defines the unique ID of the item in the List.",
				Required:    true,
			},

			"id": schema.StringAttribute{
				Description: "Defines the unique ID of the item in the List.",
				Computed:    true,
			},
			"ip": schema.StringAttribute{
				Description: "An IPv4 address, an IPv4 CIDR, an IPv6 address, or an IPv6 CIDR.",
				Computed:    true,
			},
			"hostname": schema.SingleNestedAttribute{
				Description: "Valid characters for hostnames are ASCII(7) letters from a to z, the digits from 0 to 9, wildcards (*), and the hyphen (-).",
				Computed:    true,
				CustomType:  customfield.NewNestedObjectType[ListItemHostnameDataSourceModel](ctx),
				Attributes: map[string]schema.Attribute{
					"url_hostname": schema.StringAttribute{
						Computed: true,
					},
					"exclude_exact_hostname": schema.BoolAttribute{
						Description: "Only applies to wildcard hostnames (e.g., *.example.com). When true (default), only subdomains are blocked. When false, both the root domain and subdomains are blocked.",
						Computed:    true,
					},
				},
			},
			"redirect": schema.SingleNestedAttribute{
				Description: "The definition of the redirect.",
				Computed:    true,
				CustomType:  customfield.NewNestedObjectType[ListItemRedirectDataSourceModel](ctx),
				Attributes: map[string]schema.Attribute{
					"source_url": schema.StringAttribute{
						Computed: true,
					},
					"target_url": schema.StringAttribute{
						Computed: true,
					},
					"include_subdomains": schema.BoolAttribute{
						Computed: true,
					},
					"preserve_path_suffix": schema.BoolAttribute{
						Computed: true,
					},
					"preserve_query_string": schema.BoolAttribute{
						Computed: true,
					},
					"status_code": schema.Int64Attribute{
						Description: "Available values: 301, 302, 307, 308.",
						Computed:    true,
						Validators: []validator.Int64{
							int64validator.OneOf(
								301,
								302,
								307,
								308,
							),
						},
					},
					"subpath_matching": schema.BoolAttribute{
						Computed: true,
					},
				},
			},
			"asn": schema.Int64Attribute{
				Description: "Defines a non-negative 32 bit integer.",
				Computed:    true,
			},
			"comment": schema.StringAttribute{
				Description: "Defines an informative summary of the list item.",
				Computed:    true,
			},
			"created_on": schema.StringAttribute{
				Description: "The RFC 3339 timestamp of when the list was created.",
				Computed:    true,
			},
			"modified_on": schema.StringAttribute{
				Description: "The RFC 3339 timestamp of when the list was last modified.",
				Computed:    true,
			},
		},
	}
}

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

func (d *ListItemDataSource) ConfigValidators(_ context.Context) []datasource.ConfigValidator {
	return []datasource.ConfigValidator{}
}
