import { Controller, Get, Post, Body, Param, UseGuards } from '@nestjs/common';
import { WorkOrdersService } from './work-orders.service';
import { AuthGuard } from '@nestjs/passport';

@Controller('work-orders')
@UseGuards(AuthGuard('jwt'))
export class WorkOrdersController {
    constructor(private readonly service: WorkOrdersService) { }

    @Post('from-opportunity')
    create(@Body() body: { opportunityId: string, details?: string }) {
        return this.service.createFromOpportunity(body.opportunityId, body.details);
    }

    @Get('opportunity/:id')
    findAllByOpportunity(@Param('id') id: string) {
        return this.service.findAllByOpportunity(id);
    }

    @Post(':id/payment')
    addPayment(@Param('id') id: string, @Body() body: { amount: number, mode: string }) {
        return this.service.addPayment(id, body.amount, body.mode);
    }

    @Get('stats')
    getStats() {
        return this.service.getStats();
    }
}
