import { IPaginationOptions } from 'nestjs-typeorm-paginate'
import { Body, Controller, Post, Req } from '@nestjs/common'
import { WithdrawApplyDto } from './dto/withdraw-apply.dto'
import { WithdrawService } from './withdraw.service'
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'
import { HasRoles } from '../auth/roles.decorator'
import { Role } from '../model/role.enum'
import { PageRequest } from '../common/dto/page-request'
import { Withdraw } from './entities/withdraw.entity'

@ApiTags('withdraw.admin')
@ApiBearerAuth()
@HasRoles(Role.Admin)
@Controller('/admin/withdraw')
export class WithdrawAdminController {
    constructor(private readonly withdrawService: WithdrawService) {}

    @Post()
    async list(@Body() page: PageRequest<Withdraw>) {
        return await this.withdrawService.findAll(page)
    }

    @Post('/finish')
    async apply(@Body() { id }) {
        return await this.withdrawService.finishWithdraw(id)
    }

    @Post('/reject')
    async reject(@Body() { id }) {
        return await this.withdrawService.rejectWithdraw(id)
    }
}
