// Code generated by Fern. DO NOT EDIT.

package scoreconfigs

import (
    internal "pentagi/pkg/observability/langfuse/api/internal"
    core "pentagi/pkg/observability/langfuse/api/core"
    context "context"
    api "pentagi/pkg/observability/langfuse/api"
    option "pentagi/pkg/observability/langfuse/api/option"
    http "net/http"
)


type RawClient struct {
    baseURL string
    caller *internal.Caller
    options *core.RequestOptions
}

func NewRawClient(options *core.RequestOptions) *RawClient {
    return &RawClient{
        options: options,
        baseURL: options.BaseURL,
        caller: internal.NewCaller(
            &internal.CallerParams{
                Client: options.HTTPClient,
                MaxAttempts: options.MaxAttempts,
            },
        ),
    }
}

func (r *RawClient) Get(
    ctx context.Context,
    request *api.ScoreConfigsGetRequest,
    opts ...option.RequestOption,
) (*core.Response[*api.ScoreConfigs], error){
    options := core.NewRequestOptions(opts...)
    baseURL := internal.ResolveBaseURL(
        options.BaseURL,
        r.baseURL,
        "",
    )
    endpointURL := baseURL + "/api/public/score-configs"
    queryParams, err := internal.QueryValues(request)
    if err != nil {
        return nil, err
    }
    if len(queryParams) > 0 {
        endpointURL += "?" + queryParams.Encode()
    }
    headers := internal.MergeHeaders(
        r.options.ToHeader(),
        options.ToHeader(),
    )
    var response *api.ScoreConfigs
    raw, err := r.caller.Call(
        ctx,
        &internal.CallParams{
            URL: endpointURL,
            Method: http.MethodGet,
            Headers: headers,
            MaxAttempts: options.MaxAttempts,
            BodyProperties: options.BodyProperties,
            QueryParameters: options.QueryParameters,
            Client: options.HTTPClient,
            Response: &response,
            ErrorDecoder: internal.NewErrorDecoder(api.ErrorCodes),
        },
    )
    if err != nil {
        return nil, err
    }
    return &core.Response[*api.ScoreConfigs]{
        StatusCode: raw.StatusCode,
        Header: raw.Header,
        Body: response,
    }, nil
}

func (r *RawClient) Create(
    ctx context.Context,
    request *api.CreateScoreConfigRequest,
    opts ...option.RequestOption,
) (*core.Response[*api.ScoreConfig], error){
    options := core.NewRequestOptions(opts...)
    baseURL := internal.ResolveBaseURL(
        options.BaseURL,
        r.baseURL,
        "",
    )
    endpointURL := baseURL + "/api/public/score-configs"
    headers := internal.MergeHeaders(
        r.options.ToHeader(),
        options.ToHeader(),
    )
    headers.Add("Content-Type", "application/json")
    var response *api.ScoreConfig
    raw, err := r.caller.Call(
        ctx,
        &internal.CallParams{
            URL: endpointURL,
            Method: http.MethodPost,
            Headers: headers,
            MaxAttempts: options.MaxAttempts,
            BodyProperties: options.BodyProperties,
            QueryParameters: options.QueryParameters,
            Client: options.HTTPClient,
            Request: request,
            Response: &response,
            ErrorDecoder: internal.NewErrorDecoder(api.ErrorCodes),
        },
    )
    if err != nil {
        return nil, err
    }
    return &core.Response[*api.ScoreConfig]{
        StatusCode: raw.StatusCode,
        Header: raw.Header,
        Body: response,
    }, nil
}

func (r *RawClient) GetByID(
    ctx context.Context,
    request *api.ScoreConfigsGetByIDRequest,
    opts ...option.RequestOption,
) (*core.Response[*api.ScoreConfig], error){
    options := core.NewRequestOptions(opts...)
    baseURL := internal.ResolveBaseURL(
        options.BaseURL,
        r.baseURL,
        "",
    )
    endpointURL := internal.EncodeURL(
        baseURL + "/api/public/score-configs/%v",
        request.ConfigID,
    )
    headers := internal.MergeHeaders(
        r.options.ToHeader(),
        options.ToHeader(),
    )
    var response *api.ScoreConfig
    raw, err := r.caller.Call(
        ctx,
        &internal.CallParams{
            URL: endpointURL,
            Method: http.MethodGet,
            Headers: headers,
            MaxAttempts: options.MaxAttempts,
            BodyProperties: options.BodyProperties,
            QueryParameters: options.QueryParameters,
            Client: options.HTTPClient,
            Response: &response,
            ErrorDecoder: internal.NewErrorDecoder(api.ErrorCodes),
        },
    )
    if err != nil {
        return nil, err
    }
    return &core.Response[*api.ScoreConfig]{
        StatusCode: raw.StatusCode,
        Header: raw.Header,
        Body: response,
    }, nil
}

func (r *RawClient) Update(
    ctx context.Context,
    request *api.UpdateScoreConfigRequest,
    opts ...option.RequestOption,
) (*core.Response[*api.ScoreConfig], error){
    options := core.NewRequestOptions(opts...)
    baseURL := internal.ResolveBaseURL(
        options.BaseURL,
        r.baseURL,
        "",
    )
    endpointURL := internal.EncodeURL(
        baseURL + "/api/public/score-configs/%v",
        request.ConfigID,
    )
    headers := internal.MergeHeaders(
        r.options.ToHeader(),
        options.ToHeader(),
    )
    headers.Add("Content-Type", "application/json")
    var response *api.ScoreConfig
    raw, err := r.caller.Call(
        ctx,
        &internal.CallParams{
            URL: endpointURL,
            Method: http.MethodPatch,
            Headers: headers,
            MaxAttempts: options.MaxAttempts,
            BodyProperties: options.BodyProperties,
            QueryParameters: options.QueryParameters,
            Client: options.HTTPClient,
            Request: request,
            Response: &response,
            ErrorDecoder: internal.NewErrorDecoder(api.ErrorCodes),
        },
    )
    if err != nil {
        return nil, err
    }
    return &core.Response[*api.ScoreConfig]{
        StatusCode: raw.StatusCode,
        Header: raw.Header,
        Body: response,
    }, nil
}

