import { Body, Controller, Delete, Get, Param, Post, Put, Query, Request, UseGuards } from '@nestjs/common';
import { StaffService } from './staff.service';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from '../../auth/auth.guard';
import * as dto from './dto/index';


@ApiTags('Admin Staff')
@Controller('admin/staff')
export class StaffController {

    constructor(
        private readonly StaffService: StaffService,
    ) {

    }

    @UseGuards(AuthGuard)
    @ApiBearerAuth('authorization')
    @Get('list')
    async get_admin_staff(@Query() dto: dto.staff.pagination_list, @Request() req: any) {
        try {
            let data = await this.StaffService.get_admin_staff(dto);
            let response = {
                success: true,
                message: "Staff fetch successfully",
                data: data,
            };
            return response;
        } catch (err) {
            throw err;
        }
    }

    @UseGuards(AuthGuard)
    @ApiBearerAuth('authorization')
    @Post()
    async create_admin_staff(@Body() dto: dto.staff.admin_staff_create, @Request() req: any) {
        try {
            let data = await this.StaffService.create_admin_staff(dto);
            let response = {
                success: true,
                message: "Staff created successfully",
                data: data,
            };
            return response;
        } catch (err) {
            throw err;
        }
    }

    @UseGuards(AuthGuard)
    @ApiBearerAuth('authorization')
    @Put('/:_id')
    async update_admin_staff(@Body() dto: dto.staff.admin_staff_update, @Request() req: any, @Param('_id') _id: string) {
        try {
            let data = await this.StaffService.update_admin_staff(dto, _id);
            let response = {
                success: true,
                message: "Staff updated successfully",
                data: data,
            };
            return response;
        } catch (err) {
            throw err;
        }
    }

    @UseGuards(AuthGuard)
    @ApiBearerAuth('authorization')
    @Delete('/:_id')
    async delete_admin_staff(@Request() req: any, @Param('_id') _id: string) {
        try {
            let data = await this.StaffService.delete_admin_staff(_id);
            let response = {
                success: true,
                message: "Staff deleted successfully",
                data: data,
            };
            return response;
        } catch (err) {
            throw err;
        }
    }

    @UseGuards(AuthGuard)
    @ApiBearerAuth('authorization')
    @Get('/:_id')
    async ger_admin_staff_details(@Request() req: any, @Param('_id') _id: string) {
        try {
            let data = await this.StaffService.ger_admin_staff_details(_id);
            let response = {
                success: true,
                message: "Staff found successfully",
                data: data,
            };
            return response;
        } catch (err) {
            throw err;
        }
    }

    

}
