import { Controller, Get, Post, Query, Res, UseGuards } from '@nestjs/common';
import { AlertsService } from './alerts.service';
import { UserAuthGuard } from 'src/users/auth/user.auth.guard';
import { UserDecorator } from 'src/common/decorator';
import { AlertType } from './alert.types';
import { Response } from 'express';

@Controller('alerts')
@UseGuards(UserAuthGuard)
export class AlertsController {
  constructor(private readonly alertsService: AlertsService) {}


  
@Get("all")
async getMyNotifications(
  @Res() res: Response,
  @UserDecorator() user: any,
  @Query('page') page: number = 1,
  @Query('limit') limit: number = 10,
) {
  return this.alertsService.getUserNotifications(
    res , 
    user._id,
    Number(page),
    Number(limit),
  );
}



  @Post('test')
  async sendTestAlert(@UserDecorator() user: any) {
    await this.alertsService.sendAlert(
      user._id,
      AlertType.INVOICE_PAID,
      'Test notification 🚀',
      'This is a test alert from Invoice G2G',
      {
        test: true,
        timestamp: new Date().toISOString(),
      },
    );

    return {
      success: true,
      message: 'Test alert sent (if device token exists)',
    };
  }
}
