import { Body, Controller, Get, Patch, UseGuards } from '@nestjs/common';
import { JwtAuthGuard } from '../common/guards/jwt-auth.guard';
import { CurrentUser } from '../common/decorators/current-user.decorator';
import { UsersProfileService } from './users-profile.service';
import { UpdateProfileDto } from './dto/update-profile.dto';
import { UpdateEmailDto } from './dto/update-email.dto';
import { UpdateNotificationPrefsDto } from './dto/update-notification-prefs.dto';

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

    @Get('me/profile')
    getProfile(@CurrentUser() user: { id: string; role: string }) {
        return this.profileService.getProfile(user.id, user.role);
    }

    @Patch('me/profile')
    updateProfile(
        @CurrentUser() user: { id: string; role: string },
        @Body() dto: UpdateProfileDto,
    ) {
        return this.profileService.updateProfile(user.id, user.role, dto);
    }

    @Patch('me/email')
    updateEmail(
        @CurrentUser() user: { id: string; role: string },
        @Body() dto: UpdateEmailDto,
    ) {
        return this.profileService.updateEmail(user.id, user.role, dto.email);
    }

    @Patch('me/notification-prefs')
    updateNotificationPrefs(
        @CurrentUser() user: { id: string; role: string },
        @Body() dto: UpdateNotificationPrefsDto,
    ) {
        return this.profileService.updateNotificationPrefs(user.id, user.role, dto);
    }
}
