// Code generated by protoc-gen-go-flipt-sdk. DO NOT EDIT.

package http

import (
	context "context"
	fmt "fmt"
	analytics "go.flipt.io/flipt/rpc/flipt/analytics"
	grpc "google.golang.org/grpc"
	protojson "google.golang.org/protobuf/encoding/protojson"
	io "io"
	http "net/http"
	url "net/url"
)

type AnalyticsServiceClient struct {
	client *http.Client
	addr   string
}

func (x *AnalyticsServiceClient) GetFlagEvaluationsCount(ctx context.Context, v *analytics.GetFlagEvaluationsCountRequest, _ ...grpc.CallOption) (*analytics.GetFlagEvaluationsCountResponse, error) {
	var body io.Reader
	values := url.Values{}
	values.Set("from", v.From)
	values.Set("to", v.To)
	req, err := http.NewRequestWithContext(ctx, http.MethodGet, x.addr+fmt.Sprintf("/internal/v1/analytics/namespaces/%v/flags/%v", v.NamespaceKey, v.FlagKey), body)
	if err != nil {
		return nil, err
	}
	req.URL.RawQuery = values.Encode()
	resp, err := x.client.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	var output analytics.GetFlagEvaluationsCountResponse
	respData, err := io.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	if err := checkResponse(resp, respData); err != nil {
		return nil, err
	}
	if err := (protojson.UnmarshalOptions{DiscardUnknown: true}).Unmarshal(respData, &output); err != nil {
		return nil, err
	}
	return &output, nil
}

func (t Transport) AnalyticsClient() analytics.AnalyticsServiceClient {
	return &AnalyticsServiceClient{client: t.client, addr: t.addr}
}
