package secpolicies

import (
	"context"
	"encoding/json"
	"net/http"

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

// DeleteRequest struct to move security policy
type MoveRequest struct {
	// Security policy ID
	// Required: true
	SecurityPolicyID string `url:"security_policy_id" json:"security_policy_id" validate:"required"`

	// Version ID
	// Required: true
	VersionID uint64 `url:"version_id" json:"version_id" validate:"required"`

	// Security policy ID
	// Required: true
	InsertUp string `url:"insert_up" json:"insert_up" validate:"required"`
}

// Move a security policy
func (i SecurityPolicies) Move(ctx context.Context, req MoveRequest) (*SecurityPolicySummary, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return nil, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/sdn/security_policy/move"

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

	info := SecurityPolicySummary{}

	err = json.Unmarshal(res, &info)
	if err != nil {
		return nil, err
	}

	return &info, nil
}
