// File generated from our OpenAPI spec by Stainless.

import * as Core from "../../core";
import { APIResource } from "../../resource";
import { isRequestOptions } from "../../core";
import * as SnippetsAPI from "./snippets";
import * as ContentAPI from "./content";
import * as RulesAPI from "./rules";
import { multipartFormRequestOptions } from "../../core";

export class Snippets extends APIResource {
  content: ContentAPI.Content = new ContentAPI.Content(this._client);
  rules: RulesAPI.Rules = new RulesAPI.Rules(this._client);

  /**
   * Put Snippet
   */
  update(
    zoneIdentifier: string,
    snippetName: string,
    body?: SnippetUpdateParams,
    options?: Core.RequestOptions,
  ): Core.APIPromise<Snippet>;
  update(
    zoneIdentifier: string,
    snippetName: string,
    options?: Core.RequestOptions,
  ): Core.APIPromise<Snippet>;
  update(
    zoneIdentifier: string,
    snippetName: string,
    body: SnippetUpdateParams | Core.RequestOptions = {},
    options?: Core.RequestOptions,
  ): Core.APIPromise<Snippet> {
    if (isRequestOptions(body)) {
      return this.update(zoneIdentifier, snippetName, {}, body);
    }
    return (
      this._client.put(
        `/zones/${zoneIdentifier}/snippets/${snippetName}`,
        multipartFormRequestOptions({ body, ...options }),
      ) as Core.APIPromise<{ result: Snippet }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * All Snippets
   */
  list(zoneIdentifier: string, options?: Core.RequestOptions): Core.APIPromise<SnippetListResponse> {
    return (
      this._client.get(`/zones/${zoneIdentifier}/snippets`, options) as Core.APIPromise<{
        result: SnippetListResponse;
      }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Delete Snippet
   */
  delete(
    zoneIdentifier: string,
    snippetName: string,
    options?: Core.RequestOptions,
  ): Core.APIPromise<SnippetDeleteResponse> {
    return (
      this._client.delete(`/zones/${zoneIdentifier}/snippets/${snippetName}`, options) as Core.APIPromise<{
        result: SnippetDeleteResponse;
      }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Snippet
   */
  get(zoneIdentifier: string, snippetName: string, options?: Core.RequestOptions): Core.APIPromise<Snippet> {
    return (
      this._client.get(`/zones/${zoneIdentifier}/snippets/${snippetName}`, options) as Core.APIPromise<{
        result: Snippet;
      }>
    )._thenUnwrap((obj) => obj.result);
  }
}

/**
 * Snippet Information
 */
export interface Snippet {
  /**
   * Creation time of the snippet
   */
  created_on?: string;

  /**
   * Modification time of the snippet
   */
  modified_on?: string;

  /**
   * Snippet identifying name
   */
  snippet_name?: string;
}

/**
 * List of all zone snippets
 */
export type SnippetListResponse = Array<Snippet>;

export type SnippetDeleteResponse = unknown | Array<unknown> | string;

export interface SnippetUpdateParams {
  /**
   * Content files of uploaded snippet
   */
  files?: string;

  metadata?: SnippetUpdateParams.Metadata;
}

export namespace SnippetUpdateParams {
  export interface Metadata {
    /**
     * Main module name of uploaded snippet
     */
    main_module?: string;
  }
}

export namespace Snippets {
  export import Snippet = SnippetsAPI.Snippet;
  export import SnippetListResponse = SnippetsAPI.SnippetListResponse;
  export import SnippetDeleteResponse = SnippetsAPI.SnippetDeleteResponse;
  export import SnippetUpdateParams = SnippetsAPI.SnippetUpdateParams;
  export import Content = ContentAPI.Content;
  export import Rules = RulesAPI.Rules;
  export import RuleUpdateResponse = RulesAPI.RuleUpdateResponse;
  export import RuleListResponse = RulesAPI.RuleListResponse;
  export import RuleUpdateParams = RulesAPI.RuleUpdateParams;
}
