package session

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

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

// GetRequest struct to get Session parameters
type GetRequest struct {
	// Storage endpoint provider ID
	// Required: true
	PublicSessionID string `url:"public_session_id" json:"public_session_id" validate:"required"`
}

// Get gets Session parameters as a RecordSession struct
func (s Session) Get(ctx context.Context, req GetRequest) (*RecordSession, error) {
	res, err := s.GetRaw(ctx, req)
	if err != nil {
		return nil, err
	}

	info := RecordSession{}

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

	return &info, nil
}

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

	url := "/cloudbroker/session/get"

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