/**
 * DomainException (Base)
 *
 * Base class for all translatable domain exceptions.
 * Exceptions carry an i18n key + optional args so the application-layer
 * exception filter can translate them into the caller's locale at the HTTP
 * response boundary.
 *
 * Subclasses should:
 *   - Pass an i18nKey (e.g. 'error.PORT_NOT_FOUND')
 *   - Pass i18nArgs for interpolation (e.g. { portCode })
 *   - Optionally override `status` (HTTP status, default 400)
 */

export type I18nArgs = Record<string, string | number | boolean | undefined | null>;

export abstract class DomainException extends Error {
  public readonly i18nKey: string;
  public readonly i18nArgs: I18nArgs;
  public readonly status: number;

  constructor(i18nKey: string, i18nArgs: I18nArgs = {}, fallbackMessage?: string, status = 400) {
    super(fallbackMessage ?? i18nKey);
    this.i18nKey = i18nKey;
    this.i18nArgs = i18nArgs;
    this.status = status;
    this.name = this.constructor.name;
    Object.setPrototypeOf(this, new.target.prototype);
  }
}
