import { Body, Controller, Delete, Get, Param, ParseIntPipe, Patch, Post, UseGuards } from '@nestjs/common'
import { AuthGuard } from 'src/common/guards/auth.guard'
import { CurrentUserId } from 'src/common/decorators/user-id.decorator'
import { UserId } from 'src/common/types/user-id.type'
import { KanbanService } from './kanban.service'

@Controller('kanban')
@UseGuards(AuthGuard)
export class KanbanController {
    constructor(private readonly kanban: KanbanService) { }

    @Get()
    getBoards(@CurrentUserId() userId: UserId) {
        return this.kanban.getBoards(userId)
    }

    @Post()
    createBoard(@CurrentUserId() userId: UserId, @Body('title') title: string) {
        return this.kanban.createBoard(userId, title)
    }

    @Patch(':boardId')
    updateBoard(@CurrentUserId() userId: UserId, @Param('boardId', ParseIntPipe) boardId: number, @Body('title') title: string) {
        return this.kanban.updateBoard(userId, boardId, title)
    }

    @Delete(':boardId')
    deleteBoard(@CurrentUserId() userId: UserId, @Param('boardId', ParseIntPipe) boardId: number) {
        return this.kanban.deleteBoard(userId, boardId)
    }

    @Post(':boardId/columns')
    createColumn(@CurrentUserId() userId: UserId, @Param('boardId', ParseIntPipe) boardId: number, @Body('title') title: string) {
        return this.kanban.createColumn(userId, boardId, title)
    }

    @Post('columns/:columnId/tasks')
    createTask(@CurrentUserId() userId: UserId, @Param('columnId', ParseIntPipe) columnId: number, @Body() body: { title: string; description?: string }) {
        return this.kanban.createTask(userId, columnId, body.title, body.description)
    }

    @Patch('tasks/:taskId')
    updateTask(@CurrentUserId() userId: UserId, @Param('taskId', ParseIntPipe) taskId: number, @Body() body: { title?: string; description?: string; columnId?: number; position?: number }) {
        return this.kanban.updateTask(userId, taskId, body)
    }

    @Delete('tasks/:taskId')
    deleteTask(@CurrentUserId() userId: UserId, @Param('taskId', ParseIntPipe) taskId: number) {
        return this.kanban.deleteTask(userId, taskId)
    }
}
