import { Body, Controller, Delete, Get, Param, Post, Put, Query, Request } from '@nestjs/common';
import { PhysicalExamService } from './physical-exam.service';
import { RequirePermissions } from '../../common/decorators/permissions.decorator';

@Controller('physical-exams')
export class PhysicalExamController {
  constructor(private svc: PhysicalExamService) {}

  @Get()
  @RequirePermissions('physical-exams.view')
  findAll(@Request() req: any, @Query() q: any) {
    return this.svc.findAll(req.tenant, {
      memberId: q.memberId,
      q: q.q,
      page: Number(q.page) || 1,
      limit: Number(q.limit) || 20,
    });
  }

  @Get(':id')
  @RequirePermissions('physical-exams.view')
  findOne(@Request() req: any, @Param('id') id: string) {
    return this.svc.findOne(req.tenant, id);
  }

  @Post()
  @RequirePermissions('physical-exams.create')
  create(@Request() req: any, @Body() body: any) {
    return this.svc.create(req.tenant, body, req.user?.sub, req.user?.name);
  }

  @Put(':id')
  @RequirePermissions('physical-exams.update')
  update(@Request() req: any, @Param('id') id: string, @Body() body: any) {
    return this.svc.update(req.tenant, id, body);
  }

  @Delete(':id')
  @RequirePermissions('physical-exams.delete')
  remove(@Request() req: any, @Param('id') id: string) {
    return this.svc.remove(req.tenant, id);
  }
}
