package sep

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

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

// ListAvailableSEPAndPoolsRequest struct to get dict with entry count and list of dict with SEPs and pools details accessible by the Account and RG
type ListAvailableSEPAndPoolsRequest struct {
	// Account ID
	// Required: true
	AccountID uint64 `url:"account_id" json:"account_id" validate:"required"`

	// RG ID
	// Required: false
	RGID uint64 `url:"rg_id,omitempty" json:"rg_id,omitempty"`
}

// ListAvailableSEPAndPools get dict with entry count and list of dict with SEPs and pools details accessible by the Account and RG
func (s SEP) ListAvailableSEPAndPools(ctx context.Context, req ListAvailableSEPAndPoolsRequest) (*ListAvailableSEP, error) {
	res, err := s.ListAvailableSEPAndPoolsRaw(ctx, req)
	if err != nil {
		return nil, err
	}

	list := ListAvailableSEP{}

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

	return &list, nil
}

// ListRaw gets list as an array of bytes
func (s SEP) ListAvailableSEPAndPoolsRaw(ctx context.Context, req ListAvailableSEPAndPoolsRequest) ([]byte, error) {

	err := validators.ValidateRequest(req)
	if err != nil {
		return nil, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/sep/listAvailableSepAndPools"

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