import { Body, Controller, Delete, Get, Param, Patch, Post, Query, UseGuards } from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport'
import { Roles } from 'src/auth/decorators/roles.decorator'
import { RolesGuard } from 'src/auth/guards/roles.guard'
import { BootstrapTableRequestDto } from 'src/commons/dto/bootstrap-table-request.dto'
import { CreateDetailDto } from './dto/create-detail.dto'
import { CreateHeaderDto } from './dto/create-header.dto'
import { UpdateDetailDto } from './dto/update-detail.dto'
import { UpdateHeaderDto } from './dto/update-header.dto'
import { SettingsService } from './settings.service'

@Controller('settings')
@UseGuards(AuthGuard('jwt'), RolesGuard)
export class SettingsController {
    constructor(private readonly service: SettingsService) { }

    // ===== HEADER =====

    @Post('headers')
    @Roles('SUPER_ADMIN')
    createHeader(@Body() dto: CreateHeaderDto) {
        return this.service.createHeader(dto)
    }

    @Get('headers')
    @Roles('SUPER_ADMIN', 'HEAD_STORE', 'FRONTLINER')
    findAllHeaders(@Query() query: BootstrapTableRequestDto) {
        return this.service.findAllHeaders(query)
    }

    @Get('lov-lm')
    @Roles('SUPER_ADMIN', 'HEAD_STORE', 'FRONTLINER')
    findAllLovLm(@Query() query: BootstrapTableRequestDto) {
        console.log('Fetching LOV LM with query:', query)
        return this.service.findAllLovLm(query)
    }

    @Get('lov-jewelry')
    @Roles('SUPER_ADMIN', 'HEAD_STORE', 'FRONTLINER')
    findAllLovJewelry(@Query() query: BootstrapTableRequestDto) {
        console.log('Fetching LOV Jewelry with query:', query)
        return this.service.findAllLovJewelry(query)
    }

    @Get('lov-referral-source')
    @Roles('SUPER_ADMIN', 'HEAD_STORE', 'FRONTLINER')
    findAllLovReferralSource(@Query() query: BootstrapTableRequestDto) {
        console.log('Fetching LOV referral source with query:', query)
        return this.service.findAllLovReferralSource(query)
    }

    @Get('lov-cancellation-reason')
    @Roles('SUPER_ADMIN', 'HEAD_STORE', 'FRONTLINER')
    findAllLovCancellationReason(@Query() query: BootstrapTableRequestDto) {
        console.log('Fetching LOV Cancellation Reason with query:', query)
        return this.service.findAllLovCancellationReason(query)
    }

    @Get('headers/:id')
    @Roles('SUPER_ADMIN', 'HEAD_STORE', 'FRONTLINER')
    findOneHeader(@Param('id') id: string) {
        return this.service.findOneHeader(id)
    }

    @Patch('headers/:id')
    @Roles('SUPER_ADMIN')
    updateHeader(@Param('id') id: string, @Body() dto: UpdateHeaderDto) {
        return this.service.updateHeader(id, dto)
    }

    @Delete('headers/:id')
    @Roles('SUPER_ADMIN')
    removeHeader(@Param('id') id: string) {
        return this.service.removeHeader(id)
    }

    // ===== DETAIL =====

    @Post('details')
    @Roles('SUPER_ADMIN')
    createDetail(@Body() dto: CreateDetailDto) {
        return this.service.createDetail(dto)
    }

    @Get('details')
    @Roles('SUPER_ADMIN', 'HEAD_STORE', 'FRONTLINER')
    findAllDetails(@Query() query: BootstrapTableRequestDto) {
        return this.service.findAllDetails(query)
    }

    @Get('details/:id')
    @Roles('SUPER_ADMIN', 'HEAD_STORE', 'FRONTLINER')
    findOneDetail(@Param('id') id: string) {
        return this.service.findOneDetail(id)
    }

    @Patch('details/:id')
    @Roles('SUPER_ADMIN')
    updateDetail(@Param('id') id: string, @Body() dto: UpdateDetailDto) {
        return this.service.updateDetail(id, dto)
    }

    @Delete('details/:id')
    @Roles('SUPER_ADMIN')
    removeDetail(@Param('id') id: string) {
        return this.service.removeDetail(id)
    }
}