package vins

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

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

// StaticRouteAddRequest struct to add static route
type StaticRouteAddRequest struct {
	// VINS ID
	// Required: true
	VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`

	// Destination network
	// Required: true
	Destination string `url:"destination" json:"destination" validate:"required"`

	// Destination network mask in 255.255.255.255 format
	// Required: true
	Netmask string `url:"netmask" json:"netmask" validate:"required"`

	// Next hop host, IP address from ViNS ID free IP pool
	// Required: true
	Gateway string `url:"gateway" json:"gateway" validate:"required"`
}

// StaticRouteAdd adds new static route to ViNS
func (v VINS) StaticRouteAdd(ctx context.Context, req StaticRouteAddRequest) (bool, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return false, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudapi/vins/staticRouteAdd"

	res, err := v.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
}
