package utilities

import (
	"context"

	"github.com/hashicorp/terraform-plugin-framework/diag"
	"github.com/hashicorp/terraform-plugin-log/tflog"
	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/disks"
	"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
	"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/disks/models"
)

func DataSourceDiskCheckPresence(ctx context.Context, state *models.DiskModel, c *client.Client) (*disks.RecordDisk, diag.Diagnostics) {
	diags := diag.Diagnostics{}

	listReq := disks.GetRequest{DiskID: uint64(state.DiskID.ValueInt64())}

	tflog.Info(ctx, "DataSourceDiskCheckPresence: before call CloudBroker().Disks().Get", map[string]any{
		"req": listReq,
	})

	disk, err := c.CloudBroker().Disks().Get(ctx, listReq)
	if err != nil {
		diags.AddError("Cannot get info about disk", err.Error())
		return nil, diags
	}

	tflog.Info(ctx, "DataSourceDiskCheckPresence: got successfully")
	return disk, nil
}
