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/vins"
	"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
	"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/models"
)

func VINSListDeletedDataSourceCheckPresence(ctx context.Context, plan *models.DataSourceVINSListDeletedModel, c *client.Client) (*vins.ListVINS, diag.Diagnostics) {
	tflog.Info(ctx, "VINSListDeletedDataSourceCheckPresence: Get info about vins list")

	diags := diag.Diagnostics{}

	listReq := vins.ListDeletedRequest{}
	if !plan.ByID.IsNull() {
		listReq.ByID = uint64(plan.ByID.ValueInt64())
	}
	if !plan.Name.IsNull() {
		listReq.Name = plan.Name.ValueString()
	}
	if !plan.AccountID.IsNull() {
		listReq.AccountID = uint64(plan.AccountID.ValueInt64())
	}
	if !plan.RGID.IsNull() {
		listReq.RGID = uint64(plan.RGID.ValueInt64())
	}
	if !plan.ExtIP.IsNull() {
		listReq.ExtIP = plan.ExtIP.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, "VINSListDeletedDataSourceCheckPresence: before call CloudBroker().VINS().ListDeleted", map[string]any{"req": listReq})
	list, err := c.CloudBroker().VINS().ListDeleted(ctx, listReq)
	if err != nil {
		diags.AddError("Cannot get info about vins deleted list", err.Error())
		return nil, diags
	}
	tflog.Info(ctx, "VINSListDeletedDataSourceCheckPresence: successful response from CloudBroker().VINS().ListDeleted")

	return list, nil
}
