import { Controller, Get, Post, Put, Delete, Body, Param, Query } from '@nestjs/common';
import { Roles } from '../../../common/decorators/roles.decorator';
import { CurrentUser, AuthenticatedUser } from '../../../common/decorators/current-user.decorator';
import { WorkService } from '../services/work.service';
import { CreateWorkDto, UpdateWorkDto } from '../dto/work.dto';

@Controller('works')
export class WorkController {
  constructor(private readonly workService: WorkService) {}

  @Roles('SUPERADMIN', 'SYNDIC')
  @Get()
  async getWorks(@CurrentUser() user: AuthenticatedUser, @Query('complexId') complexId: string) {
    return this.workService.getWorks(user.tenantId!, complexId);
  }

  @Roles('SUPERADMIN', 'SYNDIC')
  @Post()
  async createWork(@CurrentUser() user: AuthenticatedUser, @Body() dto: CreateWorkDto) {
    return this.workService.createWork(user.tenantId!, dto);
  }

  @Roles('SUPERADMIN', 'SYNDIC')
  @Get(':id')
  async getWork(@CurrentUser() user: AuthenticatedUser, @Param('id') id: string) {
    return this.workService.getWork(user.tenantId!, id);
  }

  @Roles('SUPERADMIN', 'SYNDIC')
  @Put(':id')
  async updateWork(@CurrentUser() user: AuthenticatedUser, @Param('id') id: string, @Body() dto: UpdateWorkDto) {
    return this.workService.updateWork(user.tenantId!, id, dto);
  }

  @Roles('SUPERADMIN', 'SYNDIC')
  @Delete(':id')
  async deleteWork(@CurrentUser() user: AuthenticatedUser, @Param('id') id: string) {
    return this.workService.deleteWork(user.tenantId!, id);
  }
}
