package utilities

import (
	"context"

	"github.com/hashicorp/terraform-plugin-log/tflog"
	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
	"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
	"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/models"
)

func ComputeSnapshotUsageCheckPresence(ctx context.Context, state *models.ListSnapShotsModel, c *client.Client) (*compute.ListUsageSnapshots, error) {
	tflog.Info(ctx, "Get compute snapshot usage info")

	req := compute.SnapshotUsageRequest{
		ComputeID: uint64(state.ComputeID.ValueInt64()),
	}
	if !state.Label.IsNull() {
		req.Label = state.Label.ValueString()
	}

	tflog.Info(ctx, "Check req", map[string]any{"req": req})

	snapshotUsage, err := c.CloudAPI().Compute().SnapshotUsage(ctx, req)
	if err != nil {
		return nil, err
	}

	tflog.Info(ctx, "Getting compute snapshot usage info, successfully")
	return &snapshotUsage, nil
}
