package secgroup

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

	"repository.basistech.ru/BASIS/dynamix-golang-sdk/v14/internal/validators"
)

type DeleteRuleRequest struct {
	// Security group ID
	// Required: true
	SecurityGroupID uint64 `url:"security_group_id" json:"security_group_id" validate:"required"`

	// Rule ID
	// Required: true
	RuleID uint64 `url:"rule_id" json:"rule_id" validate:"required"`
}

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

	url := "/cloudbroker/security_group/delete_rule"

	res, err := sg.client.DecortApiCall(ctx, http.MethodPost, url, req)
	if err != nil {
		return false, err
	}

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

	return result, nil
}
