import { Body, Controller, Get, Param, Patch, Post, Put } from '@nestjs/common'
import { PaperService } from './paper.service'
import { PageRequest } from '../common/dto/page-request'
import { PaperOrder } from './entities/paper-order.entity'
import { PaperGenResult } from './entities/paper-gen-result.entity'
import { CreatePaperOrderDto } from './dto/create-order.dto'

@Controller('paper')
export class PaperController {
    constructor(private readonly paperService: PaperService) {}

    @Post('/orders')
    async orders(@Body() page: PageRequest<PaperOrder>) {
        return await this.paperService.findAllOrders(page)
    }

    @Post('/results')
    async results(@Body() page: PageRequest<PaperGenResult>) {
        return await this.paperService.findAllResults(page)
    }

    @Put('/orders')
    async createOrder(@Body() dto: CreatePaperOrderDto) {
        return await this.paperService.createOrder(dto)
    }

    @Get('/orders/:id')
    async getOrder(@Param('id') id: string) {
        return await this.paperService.findOrderById(Number(id))
    }

    @Patch('/orders/:id')
    async updateOrder(@Param('id') id: string, @Body() data) {
        return await this.paperService.updateOrder(Number(id), data)
    }

    @Post('/orders/:id/gen')
    async gen(@Param('id') id: string) {
        return await this.paperService.gen(Number(id))
    }

    @Post('/orders/genChapters')
    async genChapters(@Body() body) {
        return await this.paperService.genChapters(body.major, body.title, body.description)
    }
}
