package utilities

import (
	"context"
	"fmt"

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

func BServiceDeletedListDataSourceCheckPresence(ctx context.Context, plan models.ListBasicServicesDelModel, c *client.Client) (*bservice.ListBasicServices, error) {
	tflog.Info(ctx, "BServiceListDataSourceCheckPresence: Get deleted list bserivce")

	accListDelReq := bservice.ListDeletedRequest{}

	if !plan.AccountID.IsNull() {
		accListDelReq.AccountID = uint64(plan.AccountID.ValueInt64())
	}
	if !plan.RGID.IsNull() {
		accListDelReq.RGID = uint64(plan.RGID.ValueInt64())
	}
	if !plan.SortBy.IsNull() {
		accListDelReq.SortBy = plan.SortBy.ValueString()
	}
	if !plan.Page.IsNull() {
		accListDelReq.Page = uint64(plan.Page.ValueInt64())
	}
	if !plan.Size.IsNull() {
		accListDelReq.Size = uint64(plan.Size.ValueInt64())
	}

	record, err := c.CloudAPI().BService().ListDeleted(ctx, accListDelReq)

	if err != nil {
		return nil, fmt.Errorf("cannot get bservice deleted list with error: %w", err)
	}

	return record, err
}
