// ═══════════════════════════════════════════════════════════════════════
// NcController — handles POST /api/nc (raise a brand-new NC)
// File: backend/src/nc/nc.controller.ts
//
// This is a NEW controller, separate from PreviousNcController. Previous NC
// is read/edit of the old QRS/TQS data; this creates fresh NCs in the new DB.
// ═══════════════════════════════════════════════════════════════════════

import {
  Body,
  Controller,
  Post,
  Req,
  UnauthorizedException,
  UseGuards,
} from '@nestjs/common';
import type { Request } from 'express';
import { CreateNcDto } from './dto/create-nc.dto';
import { NcService } from './nc.service';

// ⚠️ Use whatever auth guard the rest of your modules use:
// import { JwtAuthGuard } from '../auth/jwt-auth.guard';

@Controller('nc')
// @UseGuards(JwtAuthGuard)
export class NcController {
  constructor(private readonly ncService: NcService) {}

  @Post()
  async create(@Body() dto: CreateNcDto, @Req() req: Request) {
    const currentUserId =
      (req as any).user?.sub ?? (req as any).user?.id ?? null;
    if (!currentUserId) {
      throw new UnauthorizedException('No user id on request');
    }
    return this.ncService.create(dto, Number(currentUserId));
  }
  
}
