import { Controller, Get, Post, Body, Param, Delete, UseGuards, Req } from '@nestjs/common';
import { VisitedService } from './visited.service';
import { CreateVisitedDto } from './dto/create-visited.dto';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { AuthUserGuard } from 'src/auth/user/authUser.guard';
import { CustomUserRequest } from 'src/auth/user/interface/customUserReq';
// import { UpdateVisitedDto } from './dto/update-visited.dto';

@Controller('visited')
@ApiTags('Visited places')
export class VisitedController {
  constructor(private readonly visitedService: VisitedService) {}

  @ApiBearerAuth('jwt')
  @UseGuards(AuthUserGuard)
  @Post()
  async create(@Body() createVisitedDto: CreateVisitedDto, @Req() req: CustomUserRequest) {
    try {
      const { email } = req.user;
      return await this.visitedService.create(createVisitedDto, email);
    } catch (e) {
      return e;
    }
  }

  @Get('/getImage/:routeId')
  async getVisitedPlacesImage() {
    return await this.visitedService.getVisitedPlacesImage();
  }

  @UseGuards(AuthUserGuard)
  @ApiBearerAuth('jwt')
  @Get('/user/')
  async findAllByUser(@Req() req: CustomUserRequest) {
    const { email } = req.user;
    return this.visitedService.findAllByUser(email);
  }
}
