// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import { APIResource } from '../../core/resource';
import { APIPromise } from '../../core/api-promise';
import { PagePromise, SinglePage } from '../../core/pagination';
import { RequestOptions } from '../../internal/request-options';
import { path } from '../../internal/utils/path';

export class BaseDomains extends APIResource {
  static override readonly _key: readonly ['registrar', 'domains'] = Object.freeze([
    'registrar',
    'domains',
  ] as const);

  /**
   * Updates an individual domain.
   *
   * @deprecated This operation is deprecated and will reach end of life on September 27, 2026. Use the new Registrar API endpoints (domain-search, domain-check, registrations) instead. Refer to https://developers.cloudflare.com/fundamentals/api/reference/deprecations/ for details.
   */
  update(
    domainName: string,
    params: DomainUpdateParams,
    options?: RequestOptions,
  ): APIPromise<DomainUpdateResponse | null> {
    const { account_id, ...body } = params;
    return (
      this._client.put(path`/accounts/${account_id}/registrar/domains/${domainName}`, {
        body,
        ...options,
      }) as APIPromise<{ result: DomainUpdateResponse | null }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Lists domains handled by Registrar.
   *
   * @deprecated This operation is deprecated and will reach end of life on September 27, 2026. Use the new Registrar API endpoints (domain-search, domain-check, registrations) instead. Refer to https://developers.cloudflare.com/fundamentals/api/reference/deprecations/ for details.
   */
  list(params: DomainListParams, options?: RequestOptions): PagePromise<DomainsSinglePage, Domain> {
    const { account_id } = params;
    return this._client.getAPIList(
      path`/accounts/${account_id}/registrar/domains`,
      SinglePage<Domain>,
      options,
    );
  }

  /**
   * Show individual domain.
   *
   * @deprecated This operation is deprecated and will reach end of life on September 27, 2026. Use the new Registrar API endpoints (domain-search, domain-check, registrations) instead. Refer to https://developers.cloudflare.com/fundamentals/api/reference/deprecations/ for details.
   */
  get(
    domainName: string,
    params: DomainGetParams,
    options?: RequestOptions,
  ): APIPromise<DomainGetResponse | null> {
    const { account_id } = params;
    return (
      this._client.get(path`/accounts/${account_id}/registrar/domains/${domainName}`, options) as APIPromise<{
        result: DomainGetResponse | null;
      }>
    )._thenUnwrap((obj) => obj.result);
  }
}
export class Domains extends BaseDomains {}

export type DomainsSinglePage = SinglePage<Domain>;

export interface Domain {
  /**
   * Domain identifier.
   */
  id?: string;

  /**
   * Shows if a domain is available for transferring into Cloudflare Registrar.
   */
  available?: boolean;

  /**
   * Indicates eligibility to register the domain as a new domain.
   */
  can_register?: boolean;

  /**
   * Shows time of creation.
   */
  created_at?: string;

  /**
   * Shows name of current registrar.
   */
  current_registrar?: string;

  /**
   * Shows when domain name registration expires.
   */
  expires_at?: string;

  /**
   * Shows whether a registrar lock is in place for a domain.
   */
  locked?: boolean;

  /**
   * Shows contact information for domain registrant.
   */
  registrant_contact?: Domain.RegistrantContact;

  /**
   * A comma-separated list of registry status codes. Refer to
   * [EPP Status Codes](https://www.icann.org/resources/pages/epp-status-codes-2014-06-16-en)
   * for the full list.
   */
  registry_statuses?: string;

  /**
   * Indicates whether Cloudflare Registrar currently supports a particular TLD.
   * Refer to [TLD Policies](https://www.cloudflare.com/tld-policies/) for a list of
   * supported TLDs.
   */
  supported_tld?: boolean;

  /**
   * Statuses for domain transfers into Cloudflare Registrar.
   */
  transfer_in?: Domain.TransferIn;

  /**
   * Last updated.
   */
  updated_at?: string;
}

export namespace Domain {
  /**
   * Shows contact information for domain registrant.
   */
  export interface RegistrantContact {
    /**
     * Address.
     */
    address: string;

    /**
     * City.
     */
    city: string;

    /**
     * The country in which the user lives.
     */
    country: string | null;

    /**
     * User's first name.
     */
    first_name: string | null;

    /**
     * User's last name.
     */
    last_name: string | null;

    /**
     * Name of organization.
     */
    organization: string;

    /**
     * User's telephone number.
     */
    phone: string | null;

    /**
     * State.
     */
    state: string;

    /**
     * The zipcode or postal code where the user lives.
     */
    zip: string | null;

    /**
     * Contact Identifier.
     */
    id?: string;

    /**
     * Optional address line for unit, floor, suite, etc.
     */
    address2?: string;

    /**
     * The contact email address of the user.
     */
    email?: string;

    /**
     * Contact fax number.
     */
    fax?: string;
  }

  /**
   * Statuses for domain transfers into Cloudflare Registrar.
   */
  export interface TransferIn {
    /**
     * Status of the registrant authorization step.
     */
    accept_foa?: 'needed' | 'ok';

    /**
     * Status of the registry transfer-approval step.
     */
    approve_transfer?: 'needed' | 'ok' | 'pending' | 'trying' | 'rejected' | 'unknown';

    /**
     * Indicates if cancellation is still possible.
     */
    can_cancel_transfer?: boolean;

    /**
     * Status of the privacy-guard disabling step at the foreign registrar.
     */
    disable_privacy?: 'needed' | 'ok' | 'unknown';

    /**
     * Status of the auth-code entry and verification step.
     */
    enter_auth_code?: 'needed' | 'ok' | 'pending' | 'trying' | 'rejected';

    /**
     * Status of the domain-unlock step at the foreign registrar.
     */
    unlock_domain?: 'needed' | 'ok' | 'pending' | 'trying' | 'unknown';
  }
}

export type DomainUpdateResponse = unknown;

export type DomainGetResponse = unknown;

export interface DomainUpdateParams {
  /**
   * Path param: Identifier.
   */
  account_id: string;

  /**
   * Body param: Auto-renew controls whether subscription is automatically renewed
   * upon domain expiration.
   */
  auto_renew?: boolean;

  /**
   * Body param: Shows whether a registrar lock is in place for a domain.
   */
  locked?: boolean;

  /**
   * Body param: Privacy option controls redacting WHOIS information.
   */
  privacy?: boolean;
}

export interface DomainListParams {
  /**
   * Identifier.
   */
  account_id: string;
}

export interface DomainGetParams {
  /**
   * Identifier.
   */
  account_id: string;
}

export declare namespace Domains {
  export {
    type Domain as Domain,
    type DomainUpdateResponse as DomainUpdateResponse,
    type DomainGetResponse as DomainGetResponse,
    type DomainsSinglePage as DomainsSinglePage,
    type DomainUpdateParams as DomainUpdateParams,
    type DomainListParams as DomainListParams,
    type DomainGetParams as DomainGetParams,
  };
}
