import { Controller, Post, Get, Patch, Delete, Body, Param, Query } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { ProcurementService } from './procurement.service';
import {
  CreateVendorDto,
  UpdateVendorDto,
  CreateAcquisitionDto,
  UpdateAcquisitionDto,
  CreateDisposalDto,
} from './dto/procurement.dto';

@ApiTags('Procurement & Asset Lifecycle')
@Controller('procurement')
export class ProcurementController {
  constructor(private readonly procurementService: ProcurementService) {}

  // ---- Vendors ----
  @Post('vendors')
  @ApiOperation({ summary: 'Create a vendor' })
  async createVendor(@Body() dto: CreateVendorDto) {
    return this.procurementService.createVendor(dto);
  }

  @Get('vendors')
  @ApiOperation({ summary: 'List vendors' })
  async listVendors() {
    return this.procurementService.listVendors();
  }

  @Patch('vendors/:id')
  @ApiOperation({ summary: 'Update a vendor' })
  async updateVendor(@Param('id') id: string, @Body() dto: UpdateVendorDto) {
    return this.procurementService.updateVendor(id, dto);
  }

  @Delete('vendors/:id')
  @ApiOperation({ summary: 'Delete a vendor' })
  async deleteVendor(@Param('id') id: string) {
    return this.procurementService.deleteVendor(id);
  }

  // ---- Acquisitions ----
  @Post('acquisitions')
  @ApiOperation({ summary: 'Create an asset acquisition' })
  async createAcquisition(@Body() dto: CreateAcquisitionDto) {
    return this.procurementService.createAcquisition(dto);
  }

  @Get('acquisitions')
  @ApiOperation({ summary: 'List asset acquisitions (optionally filtered by vehicleId)' })
  async listAcquisitions(@Query('vehicleId') vehicleId?: string) {
    return this.procurementService.listAcquisitions(vehicleId);
  }

  @Get('acquisitions/:id')
  @ApiOperation({ summary: 'Get an asset acquisition by id' })
  async getAcquisition(@Param('id') id: string) {
    return this.procurementService.getAcquisition(id);
  }

  @Patch('acquisitions/:id')
  @ApiOperation({ summary: 'Update an asset acquisition' })
  async updateAcquisition(@Param('id') id: string, @Body() dto: UpdateAcquisitionDto) {
    return this.procurementService.updateAcquisition(id, dto);
  }

  @Delete('acquisitions/:id')
  @ApiOperation({ summary: 'Delete an asset acquisition' })
  async deleteAcquisition(@Param('id') id: string) {
    return this.procurementService.deleteAcquisition(id);
  }

  // ---- Disposals ----
  @Post('disposals')
  @ApiOperation({ summary: 'Create an asset disposal' })
  async createDisposal(@Body() dto: CreateDisposalDto) {
    return this.procurementService.createDisposal(dto);
  }

  @Get('disposals')
  @ApiOperation({ summary: 'List asset disposals' })
  async listDisposals() {
    return this.procurementService.listDisposals();
  }

  @Delete('disposals/:id')
  @ApiOperation({ summary: 'Delete an asset disposal' })
  async deleteDisposal(@Param('id') id: string) {
    return this.procurementService.deleteDisposal(id);
  }

  // ---- Lifecycle ----
  @Get('lifecycle/:vehicleId')
  @ApiOperation({ summary: 'Get asset lifecycle (acquisition, disposal, depreciation) for a vehicle' })
  async lifecycle(@Param('vehicleId') vehicleId: string) {
    return this.procurementService.lifecycle(vehicleId);
  }
}
