<commit_before>package algoliasearch

import (
	"encoding/json"
	"errors"
	"fmt"
	"net/http"
	"net/url"
	"time"
)

type client struct {
	appID     string
	transport *Transport
}

// NewClient instantiates a new `Client` from the provided `appID` and
// `apiKey`. Default hosts are used for the transport layer.
func NewClient(appID, apiKey string) Client {
	return &client{
		appID:     appID,
		transport: NewTransport(appID, apiKey),
	}
}

// NewClientWithHosts instantiates a new `Client` from the provided `appID` and
// `apiKey`. The transport layers' hosts are initialized with the given
// `hosts`.
func NewClientWithHosts(appID, apiKey string, hosts []string) Client {
	return &client{
		appID:     appID,
		transport: NewTransportWithHosts(appID, apiKey, hosts),
	}
}

func (c *client) GetAppID() string {
	return c.appID
}

func (c *client) SetExtraHeader(key, value string) {
	c.transport.setExtraHeader(key, value)
}

func (c *client) SetTimeout(connectTimeout, readTimeout int) {
	// As SetTimeout is about to be deprecated, we simply forward the
	// readTimeout but ignores the connectTimeout that is not longer
	// configurable.
	c.SetReadTimeout(time.Duration(readTimeout) * time.Second)
}
func (c *client) SetReadTimeout(t time.Duration)      { c.transport.setTimeouts(t, -1, -1) }
func (c *client) SetWriteTimeout(t time.Duration)     { c.transport.setTimeouts(-1, t, -1) }
func (c *client) SetAnalyticsTimeout(t time.Duration) { c.transport.setTimeouts(-1, -1, t) }

func (c *client) SetMaxIdleConnsPerHosts(maxIdleConnsPerHost int) {
	c.transport.setMaxIdleConnsPerHost(maxIdleConnsPerHost)
}

func (c *client) SetHTTPClient(client *http.Client) {
	c.transport.httpClient = client
}

func (c *client) ListIndexes() (indexes []IndexRes, err error) {
	return c.ListIndexesWithRequestOptions(nil)
}

func (c *client) ListIndexesWithRequestOptions(opts *RequestOptions) (indexes []IndexRes, err error) {
	var res listIndexesRes

	err = c.request(&res, "GET", "/1/indexes", nil, read, opts)
	indexes = res.Items
	return
}

func (c *client) InitIndex(name string) Index {
	return NewIndex(name, c)
}

func (c *client) InitAnalytics() Analytics {
	return NewAnalytics(c)
}

func (c *client) ListKeys() (keys []Key, err error) {
	return c.ListAPIKeys()
}

func (c *client) ListKeysWithRequestOptions(opts *RequestOptions) (keys []Key, err error) {
	return c.ListAPIKeysWithRequestOptions(opts)
}

func (c *client) ListAPIKeys() (keys []Key, err error) {
	return c.ListAPIKeysWithRequestOptions(nil)
}

func (c *client) ListAPIKeysWithRequestOptions(opts *RequestOptions) (keys []Key, err error) {
	var res listAPIKeysRes
	err = c.request(&res, "GET", "/1/keys", nil, read, opts)
	keys = res.Keys
	return
}

func (c *client) MoveIndex(source, destination string) (UpdateTaskRes, error) {
	return c.MoveIndexWithRequestOptions(source, destination, nil)
}

func (c *client) MoveIndexWithRequestOptions(source, destination string, opts *RequestOptions) (UpdateTaskRes, error) {
	return c.operation(source, destination, "move", nil, opts)
}

func (c *client) CopyIndex(source, destination string) (UpdateTaskRes, error) {
	return c.CopyIndexWithRequestOptions(source, destination, nil)
}

func (c *client) CopyIndexWithRequestOptions(source, destination string, opts *RequestOptions) (UpdateTaskRes, error) {
	return c.ScopedCopyIndexWithRequestOptions(source, destination, nil, opts)
}

func (c *client) ScopedCopyIndex(source, destination string, scopes []string) (UpdateTaskRes, error) {
	return c.ScopedCopyIndexWithRequestOptions(source, destination, scopes, nil)
}

func (c *client) ScopedCopyIndexWithRequestOptions(source, destination string, scopes []string, opts *RequestOptions) (UpdateTaskRes, error) {
	return c.operation(source, destination, "copy", scopes, opts)
}

func (c *client) operation(src, dst, op string, scopes []string, opts *RequestOptions) (res UpdateTaskRes, err error) {
	if err = checkScopes(scopes); err != nil {
		return
	}

	o := IndexOperation{
		Destination: dst,
		Operation:   op,
		Scopes:      scopes,
	}

	path := "/1/indexes/" + url.QueryEscape(src) + "/operation"
	err = c.request(&res, "POST", path, o, write, opts)
	return
}


func (c *client) DeleteIndex(name string) (res DeleteTaskRes, err error) {
	return c.DeleteIndexWithRequestOptions(name, nil)
}

func (c *client) DeleteIndexWithRequestOptions(name string, opts *RequestOptions) (res DeleteTaskRes, err error) {
	index := c.InitIndex(name)
	return index.DeleteWithRequestOptions(opts)
}

func (c *client) ClearIndex(name string) (res UpdateTaskRes, err error) {
	return c.ClearIndexWithRequestOptions(name, nil)
}

func (c *client) ClearIndexWithRequestOptions(name string, opts *RequestOptions) (res UpdateTaskRes, err error) {<commit_msg>changed: remove extra empty line<commit_after>package algoliasearch

import (
	"encoding/json"
	"errors"
	"fmt"
	"net/http"
	"net/url"
	"time"
)

type client struct {
	appID     string
	transport *Transport
}

// NewClient instantiates a new `Client` from the provided `appID` and
// `apiKey`. Default hosts are used for the transport layer.
func NewClient(appID, apiKey string) Client {
	return &client{
		appID:     appID,
		transport: NewTransport(appID, apiKey),
	}
}

// NewClientWithHosts instantiates a new `Client` from the provided `appID` and
// `apiKey`. The transport layers' hosts are initialized with the given
// `hosts`.
func NewClientWithHosts(appID, apiKey string, hosts []string) Client {
	return &client{
		appID:     appID,
		transport: NewTransportWithHosts(appID, apiKey, hosts),
	}
}

func (c *client) GetAppID() string {
	return c.appID
}

func (c *client) SetExtraHeader(key, value string) {
	c.transport.setExtraHeader(key, value)
}

func (c *client) SetTimeout(connectTimeout, readTimeout int) {
	// As SetTimeout is about to be deprecated, we simply forward the
	// readTimeout but ignores the connectTimeout that is not longer
	// configurable.
	c.SetReadTimeout(time.Duration(readTimeout) * time.Second)
}
func (c *client) SetReadTimeout(t time.Duration)      { c.transport.setTimeouts(t, -1, -1) }
func (c *client) SetWriteTimeout(t time.Duration)     { c.transport.setTimeouts(-1, t, -1) }
func (c *client) SetAnalyticsTimeout(t time.Duration) { c.transport.setTimeouts(-1, -1, t) }

func (c *client) SetMaxIdleConnsPerHosts(maxIdleConnsPerHost int) {
	c.transport.setMaxIdleConnsPerHost(maxIdleConnsPerHost)
}

func (c *client) SetHTTPClient(client *http.Client) {
	c.transport.httpClient = client
}

func (c *client) ListIndexes() (indexes []IndexRes, err error) {
	return c.ListIndexesWithRequestOptions(nil)
}

func (c *client) ListIndexesWithRequestOptions(opts *RequestOptions) (indexes []IndexRes, err error) {
	var res listIndexesRes

	err = c.request(&res, "GET", "/1/indexes", nil, read, opts)
	indexes = res.Items
	return
}

func (c *client) InitIndex(name string) Index {
	return NewIndex(name, c)
}

func (c *client) InitAnalytics() Analytics {
	return NewAnalytics(c)
}

func (c *client) ListKeys() (keys []Key, err error) {
	return c.ListAPIKeys()
}

func (c *client) ListKeysWithRequestOptions(opts *RequestOptions) (keys []Key, err error) {
	return c.ListAPIKeysWithRequestOptions(opts)
}

func (c *client) ListAPIKeys() (keys []Key, err error) {
	return c.ListAPIKeysWithRequestOptions(nil)
}

func (c *client) ListAPIKeysWithRequestOptions(opts *RequestOptions) (keys []Key, err error) {
	var res listAPIKeysRes
	err = c.request(&res, "GET", "/1/keys", nil, read, opts)
	keys = res.Keys
	return
}

func (c *client) MoveIndex(source, destination string) (UpdateTaskRes, error) {
	return c.MoveIndexWithRequestOptions(source, destination, nil)
}

func (c *client) MoveIndexWithRequestOptions(source, destination string, opts *RequestOptions) (UpdateTaskRes, error) {
	return c.operation(source, destination, "move", nil, opts)
}

func (c *client) CopyIndex(source, destination string) (UpdateTaskRes, error) {
	return c.CopyIndexWithRequestOptions(source, destination, nil)
}

func (c *client) CopyIndexWithRequestOptions(source, destination string, opts *RequestOptions) (UpdateTaskRes, error) {
	return c.ScopedCopyIndexWithRequestOptions(source, destination, nil, opts)
}

func (c *client) ScopedCopyIndex(source, destination string, scopes []string) (UpdateTaskRes, error) {
	return c.ScopedCopyIndexWithRequestOptions(source, destination, scopes, nil)
}

func (c *client) ScopedCopyIndexWithRequestOptions(source, destination string, scopes []string, opts *RequestOptions) (UpdateTaskRes, error) {
	return c.operation(source, destination, "copy", scopes, opts)
}

func (c *client) operation(src, dst, op string, scopes []string, opts *RequestOptions) (res UpdateTaskRes, err error) {
	if err = checkScopes(scopes); err != nil {
		return
	}

	o := IndexOperation{
		Destination: dst,
		Operation:   op,
		Scopes:      scopes,
	}

	path := "/1/indexes/" + url.QueryEscape(src) + "/operation"
	err = c.request(&res, "POST", path, o, write, opts)
	return
}

func (c *client) DeleteIndex(name string) (res DeleteTaskRes, err error) {
	return c.DeleteIndexWithRequestOptions(name, nil)
}

func (c *client) DeleteIndexWithRequestOptions(name string, opts *RequestOptions) (res DeleteTaskRes, err error) {
	index := c.InitIndex(name)
	return index.DeleteWithRequestOptions(opts)
}

func (c *client) ClearIndex(name string) (res UpdateTaskRes, err error) {
	return c.ClearIndexWithRequestOptions(name, nil)
}

func (c *client) ClearIndexWithRequestOptions(name string, opts *RequestOptions) (res UpdateTaskRes, err error) {
{'fraction_non_alphanumeric': 0.12258403361344537, 'fraction_numerical': 0.0018907563025210084, 'mean_word_length': 5.450542005420054, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2229170', 'n_tokens_mistral': 3147, 'n_tokens_neox': 3113, 'n_words': 892}