import { Body, Controller, Headers, Post, UseGuards } from '@nestjs/common';
import { RealIp } from 'src/decorators/real-ip.decorator';
import { OptionalAuthGuard } from 'src/jwt-auth/optional-auth.guard';
import { ListingEvent } from 'src/models/db.model';
import { RealIpInfo } from 'src/models/main.model';
import { EventService } from './event.service';

@Controller('event')
export class EventController {
  constructor(private eventService: EventService) {}

  @UseGuards(OptionalAuthGuard)
  @Post()
  async createEvent(
    @Body() event: ListingEvent, // Struktur des Body-Objekts entsprechend anpassen
    @RealIp() ipInfo: RealIpInfo, // IP Adresse des Clients
    @Headers('user-agent') userAgent: string, // User-Agent des Clients
  ) {
    event.userIp = ipInfo.ip;
    event.userAgent = userAgent;
    await this.eventService.createEvent(event);
    return { message: 'Event gespeichert' };
  }
}
