package utilities

import (
	"context"
	"fmt"

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

func LBListDeletedDataSourceCheckPresence(ctx context.Context, plan *models.DataSourceLBListDeleted, c *client.Client) (*lb.ListLB, error) {

	req := lb.ListDeletedRequest{}

	if !plan.ByID.IsNull() {
		req.ByID = uint64(plan.ByID.ValueInt64())
	}
	if !plan.Name.IsNull() {
		req.Name = plan.Name.ValueString()
	}
	if !plan.AccountID.IsNull() {
		req.AccountID = uint64(plan.AccountID.ValueInt64())
	}
	if !plan.RgID.IsNull() {
		req.RGID = uint64(plan.RgID.ValueInt64())
	}
	if !plan.TechStatus.IsNull() {
		req.TechStatus = plan.TechStatus.ValueString()
	}
	if !plan.FrontIP.IsNull() {
		req.FrontIP = plan.FrontIP.ValueString()
	}
	if !plan.BackIP.IsNull() {
		req.BackIP = plan.BackIP.ValueString()
	}
	if !plan.SortBy.IsNull() {
		req.SortBy = plan.SortBy.ValueString()
	}
	if !plan.Page.IsNull() {
		req.Page = uint64(plan.Page.ValueInt64())
	}
	if !plan.Size.IsNull() {
		req.Size = uint64(plan.Size.ValueInt64())
	}

	tflog.Info(ctx, "LBListDeletedDataSourceCheckPresence: before call CloudAPI().LB().ListDeleted", map[string]any{"response": req})
	lbDelList, err := c.CloudAPI().LB().ListDeleted(ctx, req)
	if err != nil {
		return nil, fmt.Errorf("cannot get info about data source list lb with error: %w", err)
	}

	tflog.Info(ctx, "LBListDeletedDataSourceCheckPresence: response from CloudAPI().LB().ListDeleted", map[string]any{"response": lbDelList})

	return lbDelList, err
}
