// note/note.controller.ts
import {
  Controller, Post, Get, Body,
  Query, Param, Req, UseGuards,
  HttpCode,
  HttpStatus,
} from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport'
import { RolesGuard } from 'src/auth/guards/roles.guard'
import { Roles } from 'src/auth/decorators/roles.decorator'
import { CreateNoteDto } from './dto/create-note.dto'
import { NotesService } from './notes.service'

@Controller('notes')
@UseGuards(AuthGuard('jwt'), RolesGuard)
export class NotesController {
  constructor(private readonly notesService: NotesService) { }

  @Post()
  @Roles('SUPER_ADMIN', 'HEAD_FINANCE', 'HEAD_STORE', 'HEAD_OPS', 'FRONTLINER')
  @HttpCode(HttpStatus.CREATED)
  async create(@Body() dto: CreateNoteDto, @Req() req) {
    const data = await this.notesService.create(dto, req.user);
    return { message: 'Note created successfully', data };
  }

  // GET /notes?entityId=<uuid>
  @Get()
  @Roles('SUPER_ADMIN', 'HEAD_FINANCE', 'HEAD_STORE', 'HEAD_OPS', 'FRONTLINER', 'STAKEHOLDERS')
  async findByEntity(@Query('entityId') entityId: string) {
    const data = await this.notesService.findByEntity(entityId);
    return { message: 'Notes fetched successfully', data };
  }
}