import { HttpException, HttpStatus } from '@nestjs/common';

export class DomainError extends Error {
  constructor(message: string) {
    super(message);
    this.name = 'DomainError';
  }
}

export class ApplicationError extends Error {
  constructor(
    message: string,
    public readonly code?: string,
  ) {
    super(message);
    this.name = 'ApplicationError';
  }
}

export class BusinessException extends HttpException {
  constructor(
    message: string,
    public readonly code?: string,
    status: HttpStatus = HttpStatus.BAD_REQUEST,
  ) {
    super({ message, code, success: false }, status);
  }
}

export class UnauthorizedException extends HttpException {
  constructor(message: string = '未授权访问') {
    super({ message, success: false }, HttpStatus.UNAUTHORIZED);
  }
}

export class NotFoundException extends HttpException {
  constructor(message: string = '资源不存在') {
    super({ message, success: false }, HttpStatus.NOT_FOUND);
  }
}
