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

@Controller('notifications')
@UseGuards(JwtAuthGuard)
export class NotificationsController {
  constructor(private readonly notificationsService: NotificationsService) {}

  @Get()
  async list(
    @CurrentUser('userId') userId: string,
    @Workspace('id') wsId: string,
    @Query() query: any,
  ) {
    return this.notificationsService.listNotifications(userId, wsId, query);
  }

  @Post('read-all')
  async markAllAsRead(
    @CurrentUser('userId') userId: string,
    @Workspace('id') wsId: string,
  ) {
    return this.notificationsService.markAllAsRead(userId, wsId);
  }

  @Post(':id/read')
  async markAsRead(
    @Param('id') id: string,
    @CurrentUser('userId') userId: string,
  ) {
    return this.notificationsService.markAsRead(id, userId);
  }

  @Get('preferences')
  async getPreferences(
    @CurrentUser('userId') userId: string,
    @Workspace('id') wsId: string,
  ) {
    return this.notificationsService.getPreferences(userId, wsId);
  }

  @Patch('preferences')
  async updatePreferences(
    @CurrentUser('userId') userId: string,
    @Workspace('id') wsId: string,
    @Body() dto: any,
  ) {
    return this.notificationsService.updatePreferences(userId, wsId, dto);
  }

  @Post('push/register')
  async registerPushToken(
    @CurrentUser('userId') userId: string,
    @Body() dto: any,
  ) {
    return this.notificationsService.registerPushToken(userId, dto);
  }

  @Delete('push/unregister')
  async unregisterPushToken(
    @CurrentUser('userId') userId: string,
    @Body('token') token: string,
  ) {
    return this.notificationsService.unregisterPushToken(userId, token);
  }

  @Get('push/tokens')
  async listPushTokens(@CurrentUser('userId') userId: string) {
    return this.notificationsService.listPushTokens(userId);
  }
}