import { HttpException } from "@nestjs/common";
import type { HttpStatus } from "@nestjs/common";
import { ErrorMessages, type ErrorCodeType } from "@customer-portal/domain/common";

/**
 * DomainHttpException
 *
 * Use this when you want to throw an HTTP error with an explicit, stable domain error code.
 * The global exception filter will read `code` from the exception response and format the
 * standard API error response for the client.
 */
export class DomainHttpException extends HttpException {
  constructor(
    public readonly code: ErrorCodeType,
    status: HttpStatus,
    message?: string
  ) {
    // `message` is optional; if omitted we fall back to the shared user-facing message.
    super({ code, message: message ?? ErrorMessages[code] }, status);
  }
}
