import { Controller, Delete, Param, Post, Request, UseGuards } from '@nestjs/common';
import { AuthGuard } from '../jwt-auth/auth.guard';
import { JwtUser } from '../models/main.model';
import { UserService } from '../user/user.service';

@Controller('listings/user')
export class UserListingsController {
  constructor(private readonly userService: UserService) { }

  @UseGuards(AuthGuard)
  @Post('favorite/:id')
  async addFavorite(@Request() req, @Param('id') id: string) {
    await this.userService.addFavorite(id, req.user as JwtUser);
    return { success: true, message: 'Added to favorites' };
  }

  @UseGuards(AuthGuard)
  @Delete('favorite/:id')
  async deleteFavorite(@Request() req, @Param('id') id: string) {
    await this.userService.deleteFavorite(id, req.user as JwtUser);
    return { success: true, message: 'Removed from favorites' };
  }

  @UseGuards(AuthGuard)
  @Post('favorites/all')
  async getFavorites(@Request() req) {
    return await this.userService.getFavoriteUsers(req.user as JwtUser);
  }
}
