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 ComputeVGPUListCheckPresence(ctx context.Context, state *models.ListVGPUsModel, c *client.Client) (*compute.ListVGPUs, error) {
	tflog.Info(ctx, "Get compute vgpu list info")

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

	if !state.GPUID.IsNull() {
		req.GPUID = uint64(state.GPUID.ValueInt64())
	}
	if !state.Type.IsNull() {
		req.Type = state.Type.ValueString()
	}
	if !state.Status.IsNull() {
		req.Status = state.Status.ValueString()
	}
	if !state.Page.IsNull() {
		req.Page = uint64(state.Page.ValueInt64())
	}
	if !state.SortBy.IsNull() {
		req.SortBy = state.SortBy.ValueString()
	}
	if !state.Size.IsNull() {
		req.Size = uint64(state.Size.ValueInt64())
	}
	if !state.IncludeDeleted.IsNull() {
		req.IncludeDeleted = state.IncludeDeleted.ValueBool()
	}

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

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

	tflog.Info(ctx, "Getting compute vgpu list info, successfully")
	return log, nil
}
