import { Controller, Post, Body, HttpCode, HttpStatus } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse, ApiBody } from '@nestjs/swagger';
import { AuthService } from './auth.service';
import {
  LoginDto,
  DigiLockerLoginDto,
  EmailPasswordLoginDto,
  LoginResponseDto,
  DigiLockerLoginResponseDto,
  UserLoginResponseDto,
} from './dto';

@ApiTags('Auth')
@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  @Post('login')
  @HttpCode(HttpStatus.OK)
  @ApiOperation({ summary: 'Login with email and password' })
  @ApiBody({ type: EmailPasswordLoginDto })
  @ApiResponse({ status: 200, description: 'Login successful', type: UserLoginResponseDto })
  @ApiResponse({ status: 401, description: 'Invalid credentials' })
  async login(@Body() dto: EmailPasswordLoginDto): Promise<UserLoginResponseDto> {
    return this.authService.emailPasswordLogin(dto);
  }

  @Post('department/login')
  @HttpCode(HttpStatus.OK)
  @ApiOperation({ summary: 'Department login with API key' })
  @ApiBody({ type: LoginDto })
  @ApiResponse({ status: 200, description: 'Login successful', type: LoginResponseDto })
  @ApiResponse({ status: 401, description: 'Invalid credentials' })
  async departmentLogin(@Body() dto: LoginDto): Promise<LoginResponseDto> {
    return this.authService.validateDepartmentApiKey(dto.apiKey, dto.departmentCode);
  }

  @Post('digilocker/login')
  @HttpCode(HttpStatus.OK)
  @ApiOperation({ summary: 'Applicant login via DigiLocker (Mock)' })
  @ApiBody({ type: DigiLockerLoginDto })
  @ApiResponse({ status: 200, description: 'Login successful', type: DigiLockerLoginResponseDto })
  @ApiResponse({ status: 401, description: 'Authentication failed' })
  async digiLockerLogin(@Body() dto: DigiLockerLoginDto): Promise<DigiLockerLoginResponseDto> {
    return this.authService.digiLockerLogin(dto);
  }
}
