package gwport

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

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

// ListRequest struct to get list of gateway ports
type ListRequest struct {
	// Router ID
	// Required: true
	RouterID string `url:"router_id" json:"router_id" validate:"required"`
}

// List gets gateway port list
func (a GWPort) List(ctx context.Context, req ListRequest) (GatewayPortsList, error) {
	res, err := a.ListRaw(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 list as an array of bytes
func (a GWPort) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return nil, validators.ValidationErrors(validators.GetErrors(err))
	}

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

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