package logicalports

import (
	"context"

	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"

	"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceLogicalPortRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
	logicalPort, err := utilityLogicalPortCheckPresence(ctx, d, m)
	if err != nil {
		d.SetId("")
		return diag.FromErr(err)
	}

	flattenLogicalPort(d, logicalPort)
	d.SetId(logicalPort.ID)
	return nil
}

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

		ReadContext: dataSourceLogicalPortRead,

		Timeouts: &schema.ResourceTimeout{
			Read:    &constants.Timeout30s,
			Default: &constants.Timeout60s,
		},
		Schema: dataSourceLogicalPortSchemaMake(),
	}
}
