import { Body, Controller, Delete, Get, Param, Post } from '@nestjs/common';
import { ProtectedMutation } from '../../common/audit/protected-mutation.decorator';
import { CreateTaskWorklogDto } from './dto/create-task-worklog.dto';
import { TaskWorklogService } from './task-worklog.service';

@Controller('task-worklogs')
export class TaskWorklogController {
  constructor(private readonly taskWorklogService: TaskWorklogService) {}

  @Get()
  findAll() {
    return this.taskWorklogService.findAll();
  }

  @Post()
  @ProtectedMutation('version.devtask:manage', { versionIdBody: 'versionId' }, {
    action: 'task_worklog.create',
    entityType: 'task_worklog',
    versionIdBody: 'versionId',
  })
  create(@Body() dto: CreateTaskWorklogDto) {
    return this.taskWorklogService.create(dto);
  }

  @Delete(':id')
  @ProtectedMutation('version.devtask:manage', {}, {
    action: 'task_worklog.delete',
    entityType: 'task_worklog',
    entityIdParam: 'id',
  })
  remove(@Param('id') id: string) {
    return this.taskWorklogService.remove(id);
  }
}
