package lb

import (
	"context"

	"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/ic"
)

func checkParamsExistence(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) diag.Diagnostics {
	errs := []error{}

	if err := ic.ExistRG(ctx, uint64(d.Get("rg_id").(int)), c); err != nil {
		errs = append(errs, err)
	}

	if err := ic.ExistExtNetInLb(ctx, uint64(d.Get("extnet_id").(int)), c); err != nil {
		errs = append(errs, err)
	}

	if err := ic.ExistVinsInLb(ctx, uint64(d.Get("vins_id").(int)), c); err != nil {
		errs = append(errs, err)
	}

	return dc.ErrorsToDiagnostics(errs)
}

func checkParamsExistenceLb(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) diag.Diagnostics {
	err := ic.ExistLB(ctx, uint64(d.Get("lb_id").(int)), c)
	return diag.FromErr(err)
}
