/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import { metricsCreate } from "../funcs/metricsCreate.js";
import { metricsGet } from "../funcs/metricsGet.js";
import { metricsList } from "../funcs/metricsList.js";
import { metricsPatch } from "../funcs/metricsPatch.js";
import { ClientSDK, RequestOptions } from "../lib/sdks.js";
import * as components from "../models/components/index.js";
import * as operations from "../models/operations/index.js";
import { unwrapAsync } from "../types/fp.js";

export class Metrics extends ClientSDK {
  /**
   * List metrics
   *
   * @remarks
   * Get a list of all metrics for the specified project.
   *
   * ### Filtering metrics
   *
   * The `filter` parameter supports the following operators: `contains`, `equals`, `anyOf`.
   *
   * #### Supported fields and operators
   *
   * You can only filter certain fields in metrics when using the `filter` parameter. Additionally, you can only filter some fields with certain operators.
   *
   * When you search for metrics, the `filter` parameter supports the following fields and operators:
   *
   * |<div style="width:120px">Field</div> |Description |Supported operators |
   * |---|---|---|
   * | `dataSourceKeys` | The data source that provides events for this metric (for example, "launchdarkly-hosted"). | `anyOf`, `notEquals` |
   * | `eventKeys` | The metric event key. | `anyOf` |
   * | `eventKind` | The metric event kind. One of `custom`, `pageview`, `click`. | `equals` |
   * | `hasConnections` | Whether the metric has connections to experiments or guarded rollouts. One of `true`, `false`. | `equals` |
   * | `isNumeric` | Whether the metric is numeric. One of `true`, `false`. | `equals` |
   * | `maintainerIds` | A comma-separated list of metric maintainer IDs. | `anyOf` |
   * | `maintainerTeamKey` | The metric maintainer team key. | `equals` |
   * | `metricUsedIn` | Filter by where the metric is used. One of `experiments`, `guarded_rollouts`, `any`, `none`. | `equals` |
   * | `query` | A "fuzzy" search across metric key and name. Supply a string or list of strings to the operator. | `equals` |
   * | `tags` | The metric tags. | `contains` |
   * | `unitAggregationType` | The metric's unit aggregation type. One of `sum`, `average`. | `equals` |
   * | `versionIds` | The metric version number. | `anyOf` |
   * | `view` | The view used to restrict access to the metric. | `equals` |
   *
   * For example, the filter `?filter=tags contains ["tag1", "tag2", "tag3"]` matches metrics that have all three tags.
   *
   * The documented values for `filter` query parameters are prior to URL encoding. For example, the `[` in `?filter=tags contains ["tag1", "tag2", "tag3"]` must be encoded to `%5B`.
   *
   * ### Expanding the metric list response
   *
   * LaunchDarkly supports expanding the "List metrics" response. By default, the expandable field is **not** included in the response.
   *
   * To expand the response, append the `expand` query parameter and add the following supported field:
   *
   * - `experimentCount` includes the number of experiments from the specific project that use the metric
   *
   * For example, `expand=experimentCount` includes the `experimentCount` field for each metric in the response.
   */
  async list(
    request: operations.GetMetricsRequest,
    options?: RequestOptions,
  ): Promise<components.MetricCollectionRep> {
    return unwrapAsync(metricsList(
      this,
      request,
      options,
    ));
  }

  /**
   * Create metric
   *
   * @remarks
   * Create a new metric in the specified project. The expected `POST` body differs depending on the specified `kind` property.
   */
  async create(
    request: operations.PostMetricRequest,
    options?: RequestOptions,
  ): Promise<components.MetricRep> {
    return unwrapAsync(metricsCreate(
      this,
      request,
      options,
    ));
  }

  /**
   * Get metric
   *
   * @remarks
   * Get information for a single metric from the specific project.
   *
   * ### Expanding the metric response
   * LaunchDarkly supports four fields for expanding the "Get metric" response. By default, these fields are **not** included in the response.
   *
   * To expand the response, append the `expand` query parameter and add a comma-separated list with any of the following fields:
   *
   * - `experiments` includes all experiments from the specific project that use the metric
   * - `experimentCount` includes the number of experiments from the specific project that use the metric
   * - `metricGroups` includes all metric groups from the specific project that use the metric
   * - `metricGroupCount` includes the number of metric groups from the specific project that use the metric
   *
   * For example, `expand=experiments` includes the `experiments` field in the response.
   */
  async get(
    request: operations.GetMetricRequest,
    options?: RequestOptions,
  ): Promise<components.MetricRep> {
    return unwrapAsync(metricsGet(
      this,
      request,
      options,
    ));
  }

  /**
   * Update metric
   *
   * @remarks
   * Patch a metric by key. Updating a metric uses a [JSON patch](https://datatracker.ietf.org/doc/html/rfc6902) representation of the desired changes. To learn more, read [Updates](https://launchdarkly.com/docs/api#updates).
   */
  async patch(
    request: operations.PatchMetricRequest,
    options?: RequestOptions,
  ): Promise<components.MetricRep> {
    return unwrapAsync(metricsPatch(
      this,
      request,
      options,
    ));
  }
}
