package defaultsecuritypolicy

import (
	"context"

	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
	log "github.com/sirupsen/logrus"
	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/defsecpolicies"
	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)

func utilityDefaultSecurityPolicyListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*defsecpolicies.SecurityPoliciesList, error) {
	c := m.(*controller.ControllerCfg)
	req := defsecpolicies.ListRequest{}

	if accessGroupID, ok := d.GetOk("access_group_id"); ok {
		req.AccessGroupID = accessGroupID.(string)
	}
	if page, ok := d.GetOk("page"); ok {
		req.Page = uint64(page.(int))
	}
	if perPage, ok := d.GetOk("per_page"); ok {
		req.PerPage = uint64(perPage.(int))
	}
	if sortBy, ok := d.GetOk("sort_by"); ok {
		req.SortBy = sortBy.(string)
	}
	if sortOrder, ok := d.GetOk("sort_order"); ok {
		req.SortOrder = sortOrder.(string)
	}

	log.Debugf("utilityDefaultSecurityPolicyListCheckPresence")
	defaultSecurityPolicyList, err := c.SDN().DefaultSecurityPolicies().List(ctx, req)
	if err != nil {
		return nil, err
	}

	return defaultSecurityPolicyList, nil
}

