import { Controller, Get, Patch, Put, Body, UseGuards, Req } from '@nestjs/common';
import { UsersService } from './users.service';
import { JwtAuthGuard } from '../../common/guards/jwt.guard';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
import { Workspace } from '../../common/decorators/workspace.decorator';

@Controller('users')
@UseGuards(JwtAuthGuard)
export class UsersController {
  constructor(private readonly usersService: UsersService) {}

  @Get()
  async listUsers(@Workspace('id') wsId: string, @Req() req: any) {
    return this.usersService.listByWorkspace(wsId);
  }

  @Get('me')
  async getMe(@CurrentUser('userId') userId: string) {
    return this.usersService.findById(userId);
  }

  @Patch('me')
  async updateMe(@CurrentUser('userId') userId: string, @Body() dto: any) {
    return this.usersService.updateProfile(userId, dto);
  }

  @Put('me/status')
  async updateStatus(@CurrentUser('userId') userId: string, @Body() dto: any) {
    return this.usersService.updateStatus(userId, dto);
  }

  @Put('me/presence')
  async updatePresence(@CurrentUser('userId') userId: string, @Body() dto: any) {
    return this.usersService.updatePresence(userId, dto.presence);
  }
}