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 ComputeCheckPresence(ctx context.Context, state *models.RecordComputeModel, c *client.Client) (*compute.RecordCompute, error) {
	tflog.Info(ctx, "Get compute info")

	req := compute.GetRequest{
		ComputeID: uint64(state.ComputeId.ValueInt64()),
	}

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

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

	tflog.Info(ctx, "Getting compute info, successfully")
	return computeRecord, nil
}

func ComputePCIDevicesListCheckPresence(ctx context.Context, state *models.RecordComputeModel, c *client.Client) (*compute.ListPCIDevices, error) {
	tflog.Info(ctx, "Get PCI devices info")

	req := compute.ListPCIDeviceRequest{
		ComputeID: uint64(state.ComputeId.ValueInt64()),
	}

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

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

	tflog.Info(ctx, "Getting PCI devices info, successfully")
	return pciDevicesList, nil
}
