import { Body, Controller, Delete, Get, Param, Post, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
import { JwtPayload } from '../../common/interfaces/jwt-payload.interface';
import { ToggleLikeDto } from './dto/toggle-like.dto';
import { LikesService } from './likes.service';

@ApiTags('Likes')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Controller('likes')
export class LikesController {
  constructor(private readonly likesService: LikesService) {}

  @Post()
  async like(@CurrentUser() user: JwtPayload, @Body() dto: ToggleLikeDto) {
    return this.likesService.like(user.sub, dto);
  }

  @Delete(':targetType/:targetId')
  async unlike(
    @CurrentUser() user: JwtPayload,
    @Param('targetId') targetId: string,
    @Param('targetType') targetType: 'post' | 'comment',
  ) {
    return this.likesService.unlike(user.sub, { targetId, targetType });
  }

  @Get('status/:targetType/:targetId')
  async getStatus(
    @CurrentUser() user: JwtPayload,
    @Param('targetId') targetId: string,
    @Param('targetType') targetType: 'post' | 'comment',
  ) {
    return this.likesService.getStatus(user.sub, { targetId, targetType });
  }

  @Post('toggle')
  async toggle(@CurrentUser() user: JwtPayload, @Body() dto: ToggleLikeDto) {
    return this.likesService.toggle(user.sub, dto);
  }
}
