package zone

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

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

// SetResourcesLimitRequest struct to set resources limit
type SetResourcesLimitRequest struct {
	// ID of the zone
	// Required: true
	ZoneID uint64 `url:"zone_id" json:"zone_id" validate:"required"`

	// Number of CPU cores reserved
	// Required: true
	ReservedCPU uint64 `url:"reserved_cpu" json:"reserved_cpu"`

	// Amount of RAM in MB reserved
	// Required: true
	ReservedRAM uint64 `url:"reserved_ram" json:"reserved_ram"`
}

// SetResourcesLimit sets reserved CPU and RAM limits for the zone
func (e Zone) SetResourcesLimit(ctx context.Context, req SetResourcesLimitRequest) (bool, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return false, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/zone/set_resources_limit"

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

	return strconv.ParseBool(string(res))
}
