package qospolicy

import (
	"context"
	"net/http"
	"strconv"

	"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
	"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)

type DeleteRuleRequest struct {
	// ID of the QoS policy
	// Required: true
	QoSPolicyID uint64 `url:"qos_policy_id" json:"qos_policy_id" validate:"required"`

	// ID of the rule to delete
	// Required: true
	RuleID uint64 `url:"rule_id" json:"rule_id" validate:"required"`
}

func (qp QoSPolicy) DeleteRule(ctx context.Context, req DeleteRuleRequest) (bool, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return false, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudapi/network_qos_policy/delete_rule"

	res, err := qp.client.DecortApiCallCtype(ctx, http.MethodDelete, url, constants.MIMEJSON, req)
	if err != nil {
		return false, err
	}

	result, err := strconv.ParseBool(string(res))
	if err != nil {
		return false, err
	}

	return result, nil
}
