package utilities

import (
	"context"

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

func K8sListDeletedCheckPresence(ctx context.Context, state *models.K8SListDeletedModel, c *client.Client) (*k8s.ListK8SClusters, error) {
	tflog.Info(ctx, "Get k8s list deleted info")

	req := k8s.ListDeletedRequest{}

	if !state.ByID.IsNull() {
		req.ByID = uint64(state.ByID.ValueInt64())
	}
	if !state.Name.IsNull() {
		req.Name = state.Name.ValueString()
	}
	if !state.IPAddress.IsNull() {
		req.IPAddress = state.IPAddress.ValueString()
	}
	if !state.RGID.IsNull() {
		req.RGID = uint64(state.RGID.ValueInt64())
	}
	if !state.LBID.IsNull() {
		req.LBID = uint64(state.LBID.ValueInt64())
	}
	if !state.BasicServiceID.IsNull() {
		req.BasicServiceID = uint64(state.BasicServiceID.ValueInt64())
	}
	if !state.TechStatus.IsNull() {
		req.TechStatus = state.TechStatus.ValueString()
	}
	if !state.SortBy.IsNull() {
		req.SortBy = state.SortBy.ValueString()
	}
	if !state.Size.IsNull() {
		req.Size = uint64(state.Size.ValueInt64())
	}
	if !state.Page.IsNull() {
		req.Page = uint64(state.Page.ValueInt64())
	}

	k8sList, err := c.CloudAPI().K8S().ListDeleted(ctx, req)
	if err != nil {
		return nil, err
	}

	tflog.Info(ctx, "Getting k8s list deleted info, successfully")
	return k8sList, nil
}
