import { Body, Controller, Get, Param, Post, Req, UseGuards } from '@nestjs/common';
import { FastFoodService } from './fast-food.service';
import { FastFoodDto } from './DTO/fastFoodDto';
import { Request } from 'express';
import { ProductDto } from './DTO/productDto';
import { AuthGuard } from '@nestjs/passport';
import { VenteDto } from './DTO/venteDto';
import { LinkModePaymentDto } from './DTO/linkModePaymentDto';

@Controller('fast-food')
export class FastFoodController {
    constructor (private readonly fastFoodService: FastFoodService){}

    @Post('create')
    create(@Body() fastFoodDto: FastFoodDto){
        return this.fastFoodService.create(fastFoodDto)
    }

    @UseGuards(AuthGuard("jwt"))
    @Post('add-product')
    addProduct(@Body() productDto: ProductDto, @Req() request: Request){
        const fastFoodId = request.user['fastFoodId']
        return this.fastFoodService.addProduct(productDto,fastFoodId)
    }

    @UseGuards(AuthGuard("jwt"))
    @Get('products')
    products(@Req() request: Request){
        const fastFoodId = request.user['fastFoodId']
        return this.fastFoodService.products(fastFoodId)
    }

    @UseGuards(AuthGuard("jwt"))
    @Post('new-vente')
    vente(@Body() venteDto: VenteDto, @Req() request: Request){
        const fastFoodId = request.user['fastFoodId']
        const userId = request.user['id']
        return this.fastFoodService.vente(venteDto, fastFoodId, userId)
    }

    @UseGuards(AuthGuard("jwt"))
    @Get('vente/details/:id')
    getVenteDetail(@Param('id') id: number){
        return this.fastFoodService.getVenteDetails(+id)
    }

    @UseGuards(AuthGuard("jwt"))
    @Get('vente/cancel/:id')
    cancelVente(@Param('id') id: number){
        return this.fastFoodService.cancelVente(+id)
    }

    @UseGuards(AuthGuard("jwt"))
    @Post('link-mode-payment')
    linkPaymentMode(@Body() limkPaymentModeDto: LinkModePaymentDto){
        return this.fastFoodService.linkPaymentMode(limkPaymentModeDto)
    }

    @UseGuards(AuthGuard("jwt"))
    @Get('mode-payment')
    getModePayment(@Req() request: Request){
        const fastFoodId = request.user['fastFoodId']
        return this.fastFoodService.getPaymentModeByFastFood(fastFoodId)
    }
    
}
