import { Controller, Post, Body, UseGuards, Req } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBody, ApiBearerAuth } from '@nestjs/swagger';
import { FcmTokensService, SaveTokenDto } from './fcm-tokens.service';

export class CreateFcmTokenDto {
    token: string;
    platform: 'web' | 'android' | 'ios';
}

@ApiTags('FCM Tokens')
@Controller('fcm-tokens')
export class FcmTokensController {
    constructor(private readonly fcmTokensService: FcmTokensService) { }

    @Post()
    @ApiOperation({ summary: 'Save FCM Token' })
    @ApiBearerAuth()
    @ApiBody({ type: CreateFcmTokenDto })
    async saveToken(@Body() body: CreateFcmTokenDto, @Req() req: any) {
        // Assuming Auth guard populates req.user
        // If not using AuthGuard, we might mock userId for now
        const userId = req.user?.id || 'mock-admin-id';

        await this.fcmTokensService.saveToken({
            ...body,
            userId,
        });

        return { message: 'Token saved' };
    }
}
