import { Controller, Request, Post, Body, Get, Res, UseGuards,Param, Put, Query, Delete, Patch } from '@nestjs/common';
import { ApiParam, ApiQuery, ApiTags, ApiBody, ApiConsumes } from '@nestjs/swagger';
import { ConfigurationsService } from './configurations.services';

import { AdminGuard } from 'src/modules/auth/guards/admin.guard';

// DTO Files
import { ConfigurationsUpdateDto } from './dtos/configurations-update.dto';
import { toJsonResponse } from 'src/common/response';

@ApiTags('configurations')
@Controller('configurations')
export class ConfigurationsController {
    constructor(private configurationsService: ConfigurationsService) { }

    // JP
    @UseGuards(AdminGuard)
    @Get('details')
    async details(@Res() response:any)
    {
        try {
            const data = await this.configurationsService.details();
            response.status(200).json(data);
        }catch (error) {
            console.log(error);
            response.status(error.status).json(toJsonResponse(error.status,error.message));
        }
    }

    // JP
    @ApiBody({ type : ConfigurationsUpdateDto })
    @UseGuards(AdminGuard)
    @Put()
    async update(@Body() request: ConfigurationsUpdateDto,@Res() response:any) {
        try {
            const data = await this.configurationsService.update(request);
            response.status(201).json();
        }catch (error) {
            response.status(error.status).json(toJsonResponse(error.status,error.message));
        }
    }
}
