package sep

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

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

// CreateRequest struct to create SEP object
type CreateRequest struct {
	// Grid ID
	// Required: true
	GID uint64 `url:"gid" json:"gid" validate:"required"`

	// SEP name
	// Required: true
	Name string `url:"name" json:"name" validate:"required"`

	// Type of storage
	// Required: true
	SEPType string `url:"sep_type" json:"sep_type" validate:"required,sepType"`

	// SEP config
	// Required: true
	Config string `url:"config" json:"config" validate:"required"`

	// Description
	// Required: false
	Description string `url:"description,omitempty" json:"description,omitempty"`

	// Enable SEP after creation
	// Required: false
	Enable bool `url:"enable,omitempty" json:"enable,omitempty"`
}

// Create creates SEP object
func (s SEP) Create(ctx context.Context, req CreateRequest) (uint64, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return 0, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/sep/create"

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

	result, err := strconv.ParseUint(string(res), 10, 64)
	if err != nil {
		return 0, err
	}

	return result, nil
}
