import { Body, Controller, Delete, Get, Param, Post, Put, Query } from '@nestjs/common'
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'
import { WebService } from './web.service'
import { PageRequest } from 'src/common/dto/page-request'
import { number } from 'yup'
import { Public } from 'src/auth/public.decorator'
import { Connect } from './entities/connect.entity'
import { Case } from './entities/case.entity'
import { HomeCase } from './entities/homeCase.entity'
import { Web } from './entities/web.entity'
import { Question } from './entities/Question.entity'
import { Ability } from './entities/ability.entity'

@ApiTags('web')
@ApiBearerAuth()
@Controller('/web')
export class WebController {
    constructor(private readonly webService: WebService) {}

    @Get('/cases')
    @Public()
    public async getCase() {
        return await this.webService.getCase()
    }

    @Post('/cases/list')
    public async findCases(@Body() page: PageRequest<Case>) {
        return await this.webService.findCases(page)
    }

    @Put('/cases/save')
    public async saveCases(@Body() connect: Partial<Case>) {
        return await this.webService.saveCases(connect)
    }

    @Put('/cases/save/:id')
    public async updateCases(@Body() connect: Partial<Case>) {
        return await this.webService.saveCases(connect)
    }

    @Delete('/cases/del/:id')
    public async delCase(@Param('id') id: string) {
        return await this.webService.delCase(Number(id))
    }

    @Get('/homeCases')
    @Public()
    public async getHomeCase() {
        return await this.webService.getHomeCase()
    }

    @Post('/homeCases')
    public async findHomeCases(@Body() page: PageRequest<HomeCase>) {
        return await this.webService.findHomeCases(page)
    }

    @Post('/homeCases/save')
    public async saveHomeCases(@Body() connect: Partial<HomeCase>) {
        return await this.webService.saveHomeCases(connect)
    }

    @Put('/homeCases/save/:id')
    public async updateHomeCases(@Body() connect: Partial<HomeCase>) {
        return await this.webService.saveHomeCases(connect)
    }

    @Delete('/homeCases/del/:id')
    public async delHomeCase(@Param('id') id: string) {
        return await this.webService.delHomeCase(Number(id))
    }

    @Get('/base')
    @Public()
    public async getBase() {
        return await this.webService.getBase()
    }

    @Post('/base')
    public async findBase(@Body() page: PageRequest<Web>) {
        return await this.webService.findBase(page)
    }

    @Put('/base/save')
    public async saveBase(@Body() connect: Partial<Web>) {
        return await this.webService.updateBase(connect)
    }

    @Put('/base/save/:id')
    public async updateBase(@Body() connect: Partial<Web>) {
        return await this.webService.updateBase(connect)
    }

    @Get('/question')
    @Public()
    public async getQuestion() {
        return await this.webService.getQuestion()
    }

    @Post('/question')
    public async findQuestion(@Body() page: PageRequest<Question>) {
        return await this.webService.findQuestion(page)
    }

    @Put('/question/save')
    public async saveQuestion(@Body() connect: Partial<Question>) {
        return await this.webService.saveQuestion(connect)
    }


    @Put('/question/save/:id')
    public async updateQuestion(@Body() connect: Partial<Question>) {
        return await this.webService.saveQuestion(connect)
    }

    @Delete('/question/del/:id')
    public async delQuestion(@Param('id') id: string) {
        return await this.webService.delQuestion(Number(id))
    }

    @Get('/ability/:id')
    @Public()
    public async getAbility(@Param('id') id: string) {
        return await this.webService.getAbility(Number(id))
    }

    @Post('/ability')
    public async findAbility(@Body() page: PageRequest<Ability>) {
        return await this.webService.findAbility(page)
    }

    @Post('/ability/save')
    public async saveAbility(@Body() connect: Partial<Ability>) {
        return await this.webService.saveAbility(connect)
    }

    @Put('/ability/save/:id')
    public async updateAbility(@Body() connect: Partial<Ability>) {
        return await this.webService.saveAbility(connect)
    }

    @Delete('/ability/del/:id')
    public async delAbility(@Param('id') id: string) {
        return await this.webService.delAbility(Number(id))
    }

    @Post('/connect/save')
    @Public()
    public async createConnect(@Body() connect: Partial<Connect>) {
        return await this.webService.saveConnect(connect)
    }

    @Post('/connect')
    public async list(@Body() page: PageRequest<Connect>) {
        return await this.webService.findConnect(page)
    }
}
