package utilities

import (
	"context"

	"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 DataSourceDiskReplicationCheckPresence(ctx context.Context, state *models.RecordDiskModel, c *client.Client) (*disks.RecordDisk, *string, error) {

	status, err := c.CloudBroker().Disks().ReplicationStatus(ctx, disks.ReplicationStatusRequest{DiskID: uint64(state.DiskId.ValueInt64())})
	if err != nil {
		return nil, nil, err
	}

	req := disks.GetRequest{}

	if !state.DiskId.IsNull() && !state.DiskId.IsUnknown() {
		req.DiskID = uint64(state.DiskId.ValueInt64())
	}

	tflog.Info(ctx, "DataSourceDiskReplicationCheckPresence: load disk")
	disk, err := c.CloudBroker().Disks().Get(ctx, req)
	if err != nil {
		return nil, nil, err
	}

	return disk, &status, nil
}
