package utilities

import (
	"context"
	"fmt"

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

func AccountListDeletedCheckPresence(ctx context.Context, plan *models.DataSourceAccountListDeletedModel, c *client.Client) (*account.ListAccounts, error) {
	tflog.Info(ctx, "AccountListDeletedCheckPresence: Get info about account list deleted")

	accListDelReq := account.ListDeletedRequest{}

	if !plan.ByID.IsNull() {
		accListDelReq.ByID = uint64(plan.ByID.ValueInt64())
	}
	if !plan.Name.IsNull() {
		accListDelReq.Name = plan.Name.ValueString()
	}
	if !plan.ACL.IsNull() {
		accListDelReq.ACL = plan.ACL.ValueString()
	}
	if !plan.Page.IsNull() {
		accListDelReq.Page = uint64(plan.Page.ValueInt64())
	}
	if !plan.Size.IsNull() {
		accListDelReq.Size = uint64(plan.Size.ValueInt64())
	}
	if !plan.SortBy.IsNull() {
		accListDelReq.SortBy = plan.SortBy.ValueString()
	}

	tflog.Info(ctx, "AccountListDeletedCheckPresence: before call CloudAPI().Account().ListDeleted", map[string]any{"req": accListDelReq})
	accListDel, err := c.CloudAPI().Account().ListDeleted(ctx, accListDelReq)
	if err != nil {
		return nil, fmt.Errorf("cannot get info about account with error: %w", err)
	}

	tflog.Info(ctx, "AccountListDeletedCheckPresence: response from CloudAPI().Account().ListDeleted")

	return accListDel, err
}
