package netobjgroups

import (
	"context"
	"net/http"

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

// AttachLogicalPortsRequest struct to attach logical ports to a network object group
type AttachLogicalPortsRequest struct {
	// ID of a network object group
	// Required: true
	ObjectGroupID string `url:"object_group_id" json:"object_group_id" validate:"required"`

	// ID of an access group
	// Required: true
	AccessGroupID string `url:"access_group_id" json:"access_group_id" validate:"required"`

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

	// Port Bindings
	// Required: true
	PortBindings []PortBindings `url:"port_bindings" json:"port_bindings" validate:"required,dive"`
}
type PortBindings struct {
	// ID of a logical port
	// Required: true
	PortID string `url:"port_id" json:"port_id" validate:"required"`

	// Version of a logical port
	// Required: true
	PortVersion int64 `url:"port_version" json:"port_version" validate:"required"`
}

// AttachLogicalPorts attaches logical ports to a network object group
func (nog NetworkObjectGroups) AttachLogicalPorts(ctx context.Context, req AttachLogicalPortsRequest) (bool, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return false, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/sdn/network_object_group/attach_logical_ports"

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

	return true, nil
}
