import { HttpStatus } from '@nestjs/common';
import { BusinessException } from '@common/exceptions/business.exception';

// ============================================================================
// Feedback Module Exceptions
// 反馈模块专用异常类
// ============================================================================

/**
 * 反馈不存在异常
 */
export class FeedbackNotFoundException extends BusinessException {
  constructor(feedbackId?: string) {
    super(
      feedbackId
        ? `反馈 ID '${feedbackId}' 不存在或已删除`
        : '反馈不存在',
      'FEEDBACK_NOT_FOUND',
      HttpStatus.NOT_FOUND,
    );
  }
}

/**
 * 反馈访问被拒绝异常
 */
export class FeedbackAccessDeniedException extends BusinessException {
  constructor(reason?: string) {
    super(
      reason || '无权访问该反馈',
      'FEEDBACK_ACCESS_DENIED',
      HttpStatus.FORBIDDEN,
      { reason },
    );
  }
}

/**
 * 无效的状态流转异常
 */
export class FeedbackInvalidStatusTransitionException extends BusinessException {
  constructor(currentStatus: string, newStatus: string) {
    super(
      `无效的状态变更：不允许从 ${currentStatus} 变更为 ${newStatus}`,
      'FEEDBACK_INVALID_STATUS_TRANSITION',
      HttpStatus.BAD_REQUEST,
      { currentStatus, newStatus },
    );
  }
}

/**
 * 附件过大异常
 */
export class FeedbackAttachmentTooLargeException extends BusinessException {
  constructor(maxSize: string = '5MB') {
    super(
      `单个附件大小超过限制（最大 ${maxSize}）`,
      'FEEDBACK_ATTACHMENT_TOO_LARGE',
      HttpStatus.BAD_REQUEST,
      { maxSize },
    );
  }
}

/**
 * 附件类型无效异常
 */
export class FeedbackAttachmentTypeInvalidException extends BusinessException {
  constructor(allowedTypes: string[] = ['png', 'jpeg', 'gif', 'webp']) {
    super(
      `附件类型不支持，仅支持: ${allowedTypes.join(', ')}`,
      'FEEDBACK_ATTACHMENT_TYPE_INVALID',
      HttpStatus.BAD_REQUEST,
      { allowedTypes },
    );
  }
}

/**
 * 附件数量超限异常
 */
export class FeedbackAttachmentsExceedLimitException extends BusinessException {
  constructor(maxCount: number = 5) {
    super(
      `附件数量超过限制（最多 ${maxCount} 个）`,
      'FEEDBACK_ATTACHMENTS_EXCEED_LIMIT',
      HttpStatus.BAD_REQUEST,
      { maxCount },
    );
  }
}

/**
 * 批量操作数量超限异常
 */
export class FeedbackBatchLimitExceededException extends BusinessException {
  constructor(maxCount: number = 100) {
    super(
      `批量操作数量超过限制（最多 ${maxCount} 个）`,
      'FEEDBACK_BATCH_LIMIT_EXCEEDED',
      HttpStatus.BAD_REQUEST,
      { maxCount },
    );
  }
}
