import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Request, Query } from '@nestjs/common';
import { AttendanceService } from './attendance.service';
import { CreateAttendanceDto } from './dto/create-attendance.dto';
import { UpdateAttendanceDto } from './dto/update-attendance.dto';
import { AuthGuard } from '@nestjs/passport';

@Controller('attendance')
@UseGuards(AuthGuard('jwt'))
export class AttendanceController {
  constructor(private readonly attendanceService: AttendanceService) { }

  @Post('check-in')
  checkIn(@Request() req, @Body() createAttendanceDto: CreateAttendanceDto) {
    return this.attendanceService.checkIn(req.user.userId, createAttendanceDto);
  }

  @Patch('check-out/:id')
  checkOut(@Param('id') id: string, @Body() updateAttendanceDto: UpdateAttendanceDto) {
    return this.attendanceService.checkOut(id, updateAttendanceDto);
  }

  @Get('my-history')
  getMyHistory(@Request() req) {
    return this.attendanceService.findMyHistory(req.user.userId);
  }

  @Get()
  findAll(@Request() req, @Query('date') date?: string) {
    return this.attendanceService.findAll(req.user, date);
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.attendanceService.findOne(id);
  }
}
