package stpolicy

import (
	"context"

	"github.com/google/uuid"
	"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)

func dataSourceStoragePolicyRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
	storagePolicy, err := utilityStoragePolicyCheckPresence(ctx, d, m)
	if err != nil {
		return diag.FromErr(err)
	}

	id := uuid.New()
	d.SetId(id.String())
	flattenStoragePolicyData(d, storagePolicy)
	return nil
}

func DataSourceStoragePolicy() *schema.Resource {
	return &schema.Resource{
		SchemaVersion: 1,

		ReadContext: dataSourceStoragePolicyRead,

		Timeouts: &schema.ResourceTimeout{
			Read:    &constants.Timeout30s,
			Default: &constants.Timeout60s,
		},

		Schema: dataSourceStoragePolicySchemaMake(),
	}
}
