package hypervisors

import (
	"context"

	"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 dataSourceHypervisorRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
	hypervisor, err := utilityHypervisorCheckPresence(ctx, d, m)
	if err != nil {
		d.SetId("")
		return diag.FromErr(err)
	}

	flattenHypervisorDataSource(d, hypervisor)
	d.SetId(hypervisor.Name)
	return nil
}

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

		ReadContext: dataSourceHypervisorRead,

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

		Schema: dataSourceHypervisorSchemaMake(),
	}
}
