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

/**
 * Entra ID 未配置异常
 */
export class EntraNotConfiguredException extends BusinessException {
  constructor(missingConfig?: string[]) {
    super(
      'ENTRA_NOT_CONFIGURED',
      'Entra ID is not configured. Please set AZURE_TENANT_ID, AZURE_CLIENT_ID, and AZURE_CLIENT_SECRET in .env',
      HttpStatus.INTERNAL_SERVER_ERROR,
      missingConfig ? { missingConfig } : undefined,
    );
  }
}

/**
 * Entra ID 认证失败异常
 */
export class EntraAuthenticationFailedException extends BusinessException {
  constructor(message?: string) {
    super(
      'ENTRA_AUTH_FAILED',
      message || 'Authentication failed against Entra ID. Please check your credentials.',
      HttpStatus.INTERNAL_SERVER_ERROR,
    );
  }
}

/**
 * Entra ID 权限不足异常
 */
export class EntraInsufficientPrivilegesException extends BusinessException {
  constructor(requiredPermissions?: string[]) {
    super(
      'INSUFFICIENT_PRIVILEGES',
      'Insufficient privileges to complete the operation. Please grant admin consent for required API permissions.',
      HttpStatus.FORBIDDEN,
      requiredPermissions ? { requiredPermissions } : undefined,
    );
  }
}

/**
 * Graph API 调用失败异常
 */
export class GraphApiException extends BusinessException {
  constructor(message: string, details?: any) {
    super('GRAPH_API_ERROR', `Graph API error: ${message}`, HttpStatus.INTERNAL_SERVER_ERROR, details);
  }
}

/**
 * 同步已在进行中异常
 */
export class SyncInProgressException extends BusinessException {
  constructor() {
    super(
      'SYNC_IN_PROGRESS',
      'Sync is already in progress. Please wait for the current sync to complete.',
      HttpStatus.CONFLICT,
    );
  }
}

/**
 * 同步失败异常
 */
export class SyncFailedException extends BusinessException {
  constructor(message: string, details?: any) {
    super('SYNC_FAILED', message, HttpStatus.INTERNAL_SERVER_ERROR, details);
  }
}
