package utilities

import (
	"context"

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

func K8CIListDeletedDataSourceCheckPresence(ctx context.Context, plan *models.DataSourceK8CIListDeletedModel, c *client.Client) (*k8ci.ListK8CI, diag.Diagnostics) {
	tflog.Info(ctx, "K8CIListDeletedDataSourceCheckPresence: Get info about k8ci list")

	diags := diag.Diagnostics{}

	listReq := k8ci.ListDeletedRequest{}
	if !plan.ByID.IsNull() {
		listReq.ByID = uint64(plan.ByID.ValueInt64())
	}
	if !plan.Name.IsNull() {
		listReq.Name = plan.Name.ValueString()
	}
	if !plan.WorkerDriver.IsNull() {
		listReq.WorkerDriver = plan.WorkerDriver.ValueString()
	}
	if !plan.MasterDriver.IsNull() {
		listReq.MasterDriver = plan.MasterDriver.ValueString()
	}
	if !plan.NetworkPlugin.IsNull() {
		listReq.NetworkPlugins = plan.NetworkPlugin.ValueString()
	}
	if !plan.SortBy.IsNull() {
		listReq.SortBy = plan.SortBy.ValueString()
	}
	if !plan.Page.IsNull() {
		listReq.Page = uint64(plan.Page.ValueInt64())
	}
	if !plan.Size.IsNull() {
		listReq.Size = uint64(plan.Size.ValueInt64())
	}

	tflog.Info(ctx, "K8CIListDeletedDataSourceCheckPresence: before call CloudBroker().K8CI().ListDeleted", map[string]any{"req": listReq})
	list, err := c.CloudBroker().K8CI().ListDeleted(ctx, listReq)
	if err != nil {
		diags.AddError("Cannot get info about k8ci deleted list", err.Error())
		return nil, diags
	}
	tflog.Info(ctx, "K8CIListDeletedDataSourceCheckPresence: successfull response from CloudBroker().K8CI().ListDeleted")

	return list, nil
}
