package gwport

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

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

// GetRequest struct to get information about gateway port
type GetRequest struct {
	// Router ID
	// Required: true
	RouterID string `url:"router_id" json:"router_id" validate:"required"`

	// Gateway port ID
	// Required: true
	GatewayPortID string `url:"gateway_port_id" json:"gateway_port_id" validate:"required"`
}

// Get gets gateway port details as a GatewayPort struct
func (a GWPort) Get(ctx context.Context, req GetRequest) (*GatewayPort, error) {
	res, err := a.GetRaw(ctx, req)
	if err != nil {
		return nil, err
	}

	info := GatewayPort{}

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

	return &info, nil

}

// GetRaw gets gateway port details as an array of bytes
func (a GWPort) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return nil, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/sdn/router/gateway_port/get"

	res, err := a.client.DecortApiCall(ctx, http.MethodGet, url, req)
	return res, err
}
