package logicalports

import (
	"context"
	"net/http"

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

// DeleteRequest struct to delete logical port
type DeleteRequest struct {
	// Port ID
	// Required: true
	ID string `url:"logical_port_id" json:"logical_port_id" validate:"required"`

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

	// Force delete. True or false
	// Required: false
	Force interface{} `url:"force,omitempty" json:"force,omitempty" validate:"omitempty,isBool"`
}

// Delete a logical port
func (i LogicalPorts) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return false, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/sdn/logical_port/delete"

	_, err = i.client.DecortApiCallCtype(ctx, http.MethodDelete, url, constants.MIMEJSON, req)
	if err != nil {
		return false, err
	}

	return true, nil
}
