import { Body, Controller, HttpException, Param, Post } from '@nestjs/common';
import { ApiOkResponse, ApiResponse, ApiTags } from '@nestjs/swagger';
import { PeriodDto } from 'src/dto';
import { SalesService } from './sales.service';

@ApiOkResponse({
    status: 200,
    description: 'Request is Successful'
})
@ApiResponse({
    status: 400,
    description: 'Bad Request / Invalid Requefst',
})
@ApiTags('Sales')
@Controller('sales')
export class SalesController {
    constructor(private readonly salesService: SalesService) {}

    @Post('so_daily_log')
    async getSalesOrderDailyLog(@Body() date_period: PeriodDto) {
        const data = await this.salesService.getSalesOrderDailyLog(date_period);
        return data;
    }
    
    @Post('sales_category_wise')
    async getSalesCategoryWise(@Body() date_period: PeriodDto) {
        const data = await this.salesService.getSalesCategoryWise(date_period);
        return data;
    }

    @Post('sales_channel_wise/:type?')
    async getSalesChannelWise(@Body() date_period: PeriodDto, @Param('type') type:(undefined|'online') ) {
        if(type && type !== 'online') {
            return new HttpException('Invalid type', 400);
        }
        const data = await this.salesService.getSalesChannelWise(date_period, type);
        return data;
    }
    

    
    @Post('sales_category_wise_new')
    async getSalesCategoryWise_new(@Body() date_period: PeriodDto) {
        const data = await this.salesService.getSalesCategoryWise_new(date_period);
        return data;
    }

    @Post('sales_channel_wise_new/:type?')
    async getSalesChannelWise_new(@Body() date_period: PeriodDto, @Param('type') type:(undefined|'online') ) {
        if(type && type !== 'online') {
            return new HttpException('Invalid type', 400);
        }
        const data = await this.salesService.getSalesChannelWise_new(date_period, type);
        return data;
    }

}
