import { Body, Controller, Get, Post, Patch, Delete, Param, UseGuards } from '@nestjs/common';
import { BookmarksService } from './bookmarks.service';
import { JwtAuthGuard } from '../../common/guards/jwt.guard';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
import { Workspace } from '../../common/decorators/workspace.decorator';

@Controller()
@UseGuards(JwtAuthGuard)
export class BookmarksController {
  constructor(private readonly bookmarksService: BookmarksService) {}

  @Get('channels/:channelId/bookmarks')
  async listByChannel(@Param('channelId') channelId: string, @Workspace('id') wsId: string) {
    return this.bookmarksService.listByChannel(channelId, wsId);
  }

  @Post('channels/:channelId/bookmarks')
  async create(
    @Param('channelId') channelId: string,
    @Workspace('id') wsId: string,
    @CurrentUser('userId') userId: string,
    @Body() dto: any,
  ) {
    return this.bookmarksService.create(channelId, wsId, userId, dto);
  }

  @Patch('bookmarks/:id')
  async update(@Param('id') id: string, @Workspace('id') wsId: string, @Body() dto: any) {
    return this.bookmarksService.update(id, wsId, dto);
  }

  @Delete('bookmarks/:id')
  async delete(@Param('id') id: string, @Workspace('id') wsId: string) {
    return this.bookmarksService.delete(id, wsId);
  }

  @Post('channels/:channelId/bookmarks/reorder')
  async reorder(
    @Param('channelId') channelId: string,
    @Workspace('id') wsId: string,
    @Body() dto: { bookmark_ids: string[] },
  ) {
    return this.bookmarksService.reorder(channelId, wsId, dto.bookmark_ids);
  }
}