/* tslint:disable */
/* eslint-disable */
/**
 * AutoGlue API
 * API for managing K3s clusters across cloud providers
 *
 * The version of the OpenAPI document: dev
 *
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

import * as runtime from "../runtime";
import type {
  DtoCreateDomainRequest,
  DtoCreateRecordSetRequest,
  DtoDomainResponse,
  DtoRecordSetResponse,
  DtoUpdateDomainRequest,
  DtoUpdateRecordSetRequest,
} from "../models/index";
import {
  DtoCreateDomainRequestFromJSON,
  DtoCreateDomainRequestToJSON,
  DtoCreateRecordSetRequestFromJSON,
  DtoCreateRecordSetRequestToJSON,
  DtoDomainResponseFromJSON,
  DtoDomainResponseToJSON,
  DtoRecordSetResponseFromJSON,
  DtoRecordSetResponseToJSON,
  DtoUpdateDomainRequestFromJSON,
  DtoUpdateDomainRequestToJSON,
  DtoUpdateRecordSetRequestFromJSON,
  DtoUpdateRecordSetRequestToJSON,
} from "../models/index";

export interface CreateDomainRequest {
  dtoCreateDomainRequest: DtoCreateDomainRequest;
  xOrgID?: string;
}

export interface CreateRecordSetRequest {
  domainId: string;
  dtoCreateRecordSetRequest: DtoCreateRecordSetRequest;
  xOrgID?: string;
}

export interface DeleteDomainRequest {
  id: string;
  xOrgID?: string;
}

export interface DeleteRecordSetRequest {
  id: string;
  xOrgID?: string;
}

export interface GetDomainRequest {
  id: string;
  xOrgID?: string;
}

export interface ListDomainsRequest {
  xOrgID?: string;
  domainName?: string;
  status?: string;
  q?: string;
}

export interface ListRecordSetsRequest {
  domainId: string;
  xOrgID?: string;
  name?: string;
  type?: string;
  status?: string;
}

export interface UpdateDomainRequest {
  id: string;
  dtoUpdateDomainRequest: DtoUpdateDomainRequest;
  xOrgID?: string;
}

export interface UpdateRecordSetRequest {
  id: string;
  dtoUpdateRecordSetRequest: DtoUpdateRecordSetRequest;
  xOrgID?: string;
}

/**
 *
 */
export class DNSApi extends runtime.BaseAPI {
  /**
   * Creates a domain bound to a Route 53 scoped credential. Archer will backfill ZoneID if omitted.
   * Create a domain (org scoped)
   */
  async createDomainRaw(
    requestParameters: CreateDomainRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<DtoDomainResponse>> {
    if (requestParameters["dtoCreateDomainRequest"] == null) {
      throw new runtime.RequiredError(
        "dtoCreateDomainRequest",
        'Required parameter "dtoCreateDomainRequest" was null or undefined when calling createDomain().',
      );
    }

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

    headerParameters["Content-Type"] = "application/json";

    if (requestParameters["xOrgID"] != null) {
      headerParameters["X-Org-ID"] = String(requestParameters["xOrgID"]);
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-KEY"] =
        await this.configuration.apiKey("X-ORG-KEY"); // OrgKeyAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-SECRET"] =
        await this.configuration.apiKey("X-ORG-SECRET"); // OrgSecretAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["Authorization"] =
        await this.configuration.apiKey("Authorization"); // BearerAuth authentication
    }

    let urlPath = `/dns/domains`;

    const response = await this.request(
      {
        path: urlPath,
        method: "POST",
        headers: headerParameters,
        query: queryParameters,
        body: DtoCreateDomainRequestToJSON(
          requestParameters["dtoCreateDomainRequest"],
        ),
      },
      initOverrides,
    );

    return new runtime.JSONApiResponse(response, (jsonValue) =>
      DtoDomainResponseFromJSON(jsonValue),
    );
  }

  /**
   * Creates a domain bound to a Route 53 scoped credential. Archer will backfill ZoneID if omitted.
   * Create a domain (org scoped)
   */
  async createDomain(
    requestParameters: CreateDomainRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<DtoDomainResponse> {
    const response = await this.createDomainRaw(
      requestParameters,
      initOverrides,
    );
    return await response.value();
  }

  /**
   * Create a record set (pending; Archer will UPSERT to Route 53)
   */
  async createRecordSetRaw(
    requestParameters: CreateRecordSetRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<DtoRecordSetResponse>> {
    if (requestParameters["domainId"] == null) {
      throw new runtime.RequiredError(
        "domainId",
        'Required parameter "domainId" was null or undefined when calling createRecordSet().',
      );
    }

    if (requestParameters["dtoCreateRecordSetRequest"] == null) {
      throw new runtime.RequiredError(
        "dtoCreateRecordSetRequest",
        'Required parameter "dtoCreateRecordSetRequest" was null or undefined when calling createRecordSet().',
      );
    }

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

    headerParameters["Content-Type"] = "application/json";

    if (requestParameters["xOrgID"] != null) {
      headerParameters["X-Org-ID"] = String(requestParameters["xOrgID"]);
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-KEY"] =
        await this.configuration.apiKey("X-ORG-KEY"); // OrgKeyAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-SECRET"] =
        await this.configuration.apiKey("X-ORG-SECRET"); // OrgSecretAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["Authorization"] =
        await this.configuration.apiKey("Authorization"); // BearerAuth authentication
    }

    let urlPath = `/dns/domains/{domain_id}/records`;
    urlPath = urlPath.replace(
      `{${"domain_id"}}`,
      encodeURIComponent(String(requestParameters["domainId"])),
    );

    const response = await this.request(
      {
        path: urlPath,
        method: "POST",
        headers: headerParameters,
        query: queryParameters,
        body: DtoCreateRecordSetRequestToJSON(
          requestParameters["dtoCreateRecordSetRequest"],
        ),
      },
      initOverrides,
    );

    return new runtime.JSONApiResponse(response, (jsonValue) =>
      DtoRecordSetResponseFromJSON(jsonValue),
    );
  }

  /**
   * Create a record set (pending; Archer will UPSERT to Route 53)
   */
  async createRecordSet(
    requestParameters: CreateRecordSetRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<DtoRecordSetResponse> {
    const response = await this.createRecordSetRaw(
      requestParameters,
      initOverrides,
    );
    return await response.value();
  }

  /**
   * Delete a domain
   */
  async deleteDomainRaw(
    requestParameters: DeleteDomainRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<void>> {
    if (requestParameters["id"] == null) {
      throw new runtime.RequiredError(
        "id",
        'Required parameter "id" was null or undefined when calling deleteDomain().',
      );
    }

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

    if (requestParameters["xOrgID"] != null) {
      headerParameters["X-Org-ID"] = String(requestParameters["xOrgID"]);
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-KEY"] =
        await this.configuration.apiKey("X-ORG-KEY"); // OrgKeyAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-SECRET"] =
        await this.configuration.apiKey("X-ORG-SECRET"); // OrgSecretAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["Authorization"] =
        await this.configuration.apiKey("Authorization"); // BearerAuth authentication
    }

    let urlPath = `/dns/domains/{id}`;
    urlPath = urlPath.replace(
      `{${"id"}}`,
      encodeURIComponent(String(requestParameters["id"])),
    );

    const response = await this.request(
      {
        path: urlPath,
        method: "DELETE",
        headers: headerParameters,
        query: queryParameters,
      },
      initOverrides,
    );

    return new runtime.VoidApiResponse(response);
  }

  /**
   * Delete a domain
   */
  async deleteDomain(
    requestParameters: DeleteDomainRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<void> {
    await this.deleteDomainRaw(requestParameters, initOverrides);
  }

  /**
   * Delete a record set (API removes row; worker can optionally handle external deletion policy)
   */
  async deleteRecordSetRaw(
    requestParameters: DeleteRecordSetRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<void>> {
    if (requestParameters["id"] == null) {
      throw new runtime.RequiredError(
        "id",
        'Required parameter "id" was null or undefined when calling deleteRecordSet().',
      );
    }

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

    if (requestParameters["xOrgID"] != null) {
      headerParameters["X-Org-ID"] = String(requestParameters["xOrgID"]);
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-KEY"] =
        await this.configuration.apiKey("X-ORG-KEY"); // OrgKeyAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-SECRET"] =
        await this.configuration.apiKey("X-ORG-SECRET"); // OrgSecretAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["Authorization"] =
        await this.configuration.apiKey("Authorization"); // BearerAuth authentication
    }

    let urlPath = `/dns/records/{id}`;
    urlPath = urlPath.replace(
      `{${"id"}}`,
      encodeURIComponent(String(requestParameters["id"])),
    );

    const response = await this.request(
      {
        path: urlPath,
        method: "DELETE",
        headers: headerParameters,
        query: queryParameters,
      },
      initOverrides,
    );

    return new runtime.VoidApiResponse(response);
  }

  /**
   * Delete a record set (API removes row; worker can optionally handle external deletion policy)
   */
  async deleteRecordSet(
    requestParameters: DeleteRecordSetRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<void> {
    await this.deleteRecordSetRaw(requestParameters, initOverrides);
  }

  /**
   * Get a domain (org scoped)
   */
  async getDomainRaw(
    requestParameters: GetDomainRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<DtoDomainResponse>> {
    if (requestParameters["id"] == null) {
      throw new runtime.RequiredError(
        "id",
        'Required parameter "id" was null or undefined when calling getDomain().',
      );
    }

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

    if (requestParameters["xOrgID"] != null) {
      headerParameters["X-Org-ID"] = String(requestParameters["xOrgID"]);
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-KEY"] =
        await this.configuration.apiKey("X-ORG-KEY"); // OrgKeyAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-SECRET"] =
        await this.configuration.apiKey("X-ORG-SECRET"); // OrgSecretAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["Authorization"] =
        await this.configuration.apiKey("Authorization"); // BearerAuth authentication
    }

    let urlPath = `/dns/domains/{id}`;
    urlPath = urlPath.replace(
      `{${"id"}}`,
      encodeURIComponent(String(requestParameters["id"])),
    );

    const response = await this.request(
      {
        path: urlPath,
        method: "GET",
        headers: headerParameters,
        query: queryParameters,
      },
      initOverrides,
    );

    return new runtime.JSONApiResponse(response, (jsonValue) =>
      DtoDomainResponseFromJSON(jsonValue),
    );
  }

  /**
   * Get a domain (org scoped)
   */
  async getDomain(
    requestParameters: GetDomainRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<DtoDomainResponse> {
    const response = await this.getDomainRaw(requestParameters, initOverrides);
    return await response.value();
  }

  /**
   * Returns domains for X-Org-ID. Filters: `domain_name`, `status`, `q` (contains).
   * List domains (org scoped)
   */
  async listDomainsRaw(
    requestParameters: ListDomainsRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<Array<DtoDomainResponse>>> {
    const queryParameters: any = {};

    if (requestParameters["domainName"] != null) {
      queryParameters["domain_name"] = requestParameters["domainName"];
    }

    if (requestParameters["status"] != null) {
      queryParameters["status"] = requestParameters["status"];
    }

    if (requestParameters["q"] != null) {
      queryParameters["q"] = requestParameters["q"];
    }

    const headerParameters: runtime.HTTPHeaders = {};

    if (requestParameters["xOrgID"] != null) {
      headerParameters["X-Org-ID"] = String(requestParameters["xOrgID"]);
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-KEY"] =
        await this.configuration.apiKey("X-ORG-KEY"); // OrgKeyAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-SECRET"] =
        await this.configuration.apiKey("X-ORG-SECRET"); // OrgSecretAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["Authorization"] =
        await this.configuration.apiKey("Authorization"); // BearerAuth authentication
    }

    let urlPath = `/dns/domains`;

    const response = await this.request(
      {
        path: urlPath,
        method: "GET",
        headers: headerParameters,
        query: queryParameters,
      },
      initOverrides,
    );

    return new runtime.JSONApiResponse(response, (jsonValue) =>
      jsonValue.map(DtoDomainResponseFromJSON),
    );
  }

  /**
   * Returns domains for X-Org-ID. Filters: `domain_name`, `status`, `q` (contains).
   * List domains (org scoped)
   */
  async listDomains(
    requestParameters: ListDomainsRequest = {},
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<Array<DtoDomainResponse>> {
    const response = await this.listDomainsRaw(
      requestParameters,
      initOverrides,
    );
    return await response.value();
  }

  /**
   * Filters: `name`, `type`, `status`.
   * List record sets for a domain
   */
  async listRecordSetsRaw(
    requestParameters: ListRecordSetsRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<Array<DtoRecordSetResponse>>> {
    if (requestParameters["domainId"] == null) {
      throw new runtime.RequiredError(
        "domainId",
        'Required parameter "domainId" was null or undefined when calling listRecordSets().',
      );
    }

    const queryParameters: any = {};

    if (requestParameters["name"] != null) {
      queryParameters["name"] = requestParameters["name"];
    }

    if (requestParameters["type"] != null) {
      queryParameters["type"] = requestParameters["type"];
    }

    if (requestParameters["status"] != null) {
      queryParameters["status"] = requestParameters["status"];
    }

    const headerParameters: runtime.HTTPHeaders = {};

    if (requestParameters["xOrgID"] != null) {
      headerParameters["X-Org-ID"] = String(requestParameters["xOrgID"]);
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-KEY"] =
        await this.configuration.apiKey("X-ORG-KEY"); // OrgKeyAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-SECRET"] =
        await this.configuration.apiKey("X-ORG-SECRET"); // OrgSecretAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["Authorization"] =
        await this.configuration.apiKey("Authorization"); // BearerAuth authentication
    }

    let urlPath = `/dns/domains/{domain_id}/records`;
    urlPath = urlPath.replace(
      `{${"domain_id"}}`,
      encodeURIComponent(String(requestParameters["domainId"])),
    );

    const response = await this.request(
      {
        path: urlPath,
        method: "GET",
        headers: headerParameters,
        query: queryParameters,
      },
      initOverrides,
    );

    return new runtime.JSONApiResponse(response, (jsonValue) =>
      jsonValue.map(DtoRecordSetResponseFromJSON),
    );
  }

  /**
   * Filters: `name`, `type`, `status`.
   * List record sets for a domain
   */
  async listRecordSets(
    requestParameters: ListRecordSetsRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<Array<DtoRecordSetResponse>> {
    const response = await this.listRecordSetsRaw(
      requestParameters,
      initOverrides,
    );
    return await response.value();
  }

  /**
   * Update a domain (org scoped)
   */
  async updateDomainRaw(
    requestParameters: UpdateDomainRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<DtoDomainResponse>> {
    if (requestParameters["id"] == null) {
      throw new runtime.RequiredError(
        "id",
        'Required parameter "id" was null or undefined when calling updateDomain().',
      );
    }

    if (requestParameters["dtoUpdateDomainRequest"] == null) {
      throw new runtime.RequiredError(
        "dtoUpdateDomainRequest",
        'Required parameter "dtoUpdateDomainRequest" was null or undefined when calling updateDomain().',
      );
    }

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

    headerParameters["Content-Type"] = "application/json";

    if (requestParameters["xOrgID"] != null) {
      headerParameters["X-Org-ID"] = String(requestParameters["xOrgID"]);
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-KEY"] =
        await this.configuration.apiKey("X-ORG-KEY"); // OrgKeyAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-SECRET"] =
        await this.configuration.apiKey("X-ORG-SECRET"); // OrgSecretAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["Authorization"] =
        await this.configuration.apiKey("Authorization"); // BearerAuth authentication
    }

    let urlPath = `/dns/domains/{id}`;
    urlPath = urlPath.replace(
      `{${"id"}}`,
      encodeURIComponent(String(requestParameters["id"])),
    );

    const response = await this.request(
      {
        path: urlPath,
        method: "PATCH",
        headers: headerParameters,
        query: queryParameters,
        body: DtoUpdateDomainRequestToJSON(
          requestParameters["dtoUpdateDomainRequest"],
        ),
      },
      initOverrides,
    );

    return new runtime.JSONApiResponse(response, (jsonValue) =>
      DtoDomainResponseFromJSON(jsonValue),
    );
  }

  /**
   * Update a domain (org scoped)
   */
  async updateDomain(
    requestParameters: UpdateDomainRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<DtoDomainResponse> {
    const response = await this.updateDomainRaw(
      requestParameters,
      initOverrides,
    );
    return await response.value();
  }

  /**
   * Update a record set (flips to pending for reconciliation)
   */
  async updateRecordSetRaw(
    requestParameters: UpdateRecordSetRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<DtoRecordSetResponse>> {
    if (requestParameters["id"] == null) {
      throw new runtime.RequiredError(
        "id",
        'Required parameter "id" was null or undefined when calling updateRecordSet().',
      );
    }

    if (requestParameters["dtoUpdateRecordSetRequest"] == null) {
      throw new runtime.RequiredError(
        "dtoUpdateRecordSetRequest",
        'Required parameter "dtoUpdateRecordSetRequest" was null or undefined when calling updateRecordSet().',
      );
    }

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

    headerParameters["Content-Type"] = "application/json";

    if (requestParameters["xOrgID"] != null) {
      headerParameters["X-Org-ID"] = String(requestParameters["xOrgID"]);
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-KEY"] =
        await this.configuration.apiKey("X-ORG-KEY"); // OrgKeyAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-SECRET"] =
        await this.configuration.apiKey("X-ORG-SECRET"); // OrgSecretAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["Authorization"] =
        await this.configuration.apiKey("Authorization"); // BearerAuth authentication
    }

    let urlPath = `/dns/records/{id}`;
    urlPath = urlPath.replace(
      `{${"id"}}`,
      encodeURIComponent(String(requestParameters["id"])),
    );

    const response = await this.request(
      {
        path: urlPath,
        method: "PATCH",
        headers: headerParameters,
        query: queryParameters,
        body: DtoUpdateRecordSetRequestToJSON(
          requestParameters["dtoUpdateRecordSetRequest"],
        ),
      },
      initOverrides,
    );

    return new runtime.JSONApiResponse(response, (jsonValue) =>
      DtoRecordSetResponseFromJSON(jsonValue),
    );
  }

  /**
   * Update a record set (flips to pending for reconciliation)
   */
  async updateRecordSet(
    requestParameters: UpdateRecordSetRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<DtoRecordSetResponse> {
    const response = await this.updateRecordSetRaw(
      requestParameters,
      initOverrides,
    );
    return await response.value();
  }
}
