import { Body, Controller, Get, Param, Post, Put, Query, Request, UseGuards } from '@nestjs/common';
import { PagesService } from './pages.service';
import { ApiBearerAuth, ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { AuthGuard } from 'src/auth/auth.guard';
import { RolesGuard } from 'src/guard/role.guard';
import { Roles } from 'src/guard/decorators/role.decorator';
import { STAFF_ROLES, UserType } from '../user/schema/users.schema';
import * as dto from './dto';

@ApiTags('Pages')
@Controller('pages')
export class PagesController {
    constructor(
        private readonly pageService: PagesService
    ) { }

    @UseGuards(AuthGuard, RolesGuard)
    @Roles(UserType.SUPER_ADMIN, ...STAFF_ROLES)
    @ApiBearerAuth('authorization')
    @Post('faqs')
    async createFAQs(@Query() queryDto: dto.pages.AddFAQsDto) {
        return this.pageService.createFaqs(queryDto.question, queryDto.answere);
    }


    @UseGuards(AuthGuard, RolesGuard)
    @Roles(UserType.SUPER_ADMIN, ...STAFF_ROLES)
    @ApiBearerAuth('authorization')
    @Get('')
    async getAllCrmData(@Query() queryDto: dto.pages.PagesListDto) {
        return this.pageService.getAllpagesData(queryDto);
    }

    @Get('/:type')
    async getByPageTypes(@Param('type') type: string) {
        return this.pageService.getByPageTypes(type);
    }

    @UseGuards(AuthGuard, RolesGuard)
    @Roles(UserType.SUPER_ADMIN, ...STAFF_ROLES)
    @ApiBearerAuth('authorization')
    @Put('/:id')
    async updatePage(@Param('id') id: string, @Body() bodyDto: dto.pages.EditPagesDto) {
        return this.pageService.updatePageTypes(id, bodyDto);
    }
}
