import { Controller, Post, Get, Patch, Delete, Body, Param, Query } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { ComplianceService } from './compliance.service';
import {
  CreateComplianceRecordDto,
  UpdateComplianceRecordDto,
} from './dto/create-compliance-record.dto';
import { ComplianceType } from './entities/compliance-record.entity';

@ApiTags('Vehicle Compliance')
@Controller('compliance')
export class ComplianceController {
  constructor(private readonly complianceService: ComplianceService) {}

  @Post()
  @ApiOperation({ summary: 'Create a compliance record' })
  create(@Body() dto: CreateComplianceRecordDto) {
    return this.complianceService.create(dto);
  }

  @Get()
  @ApiOperation({ summary: 'List compliance records' })
  findAll(
    @Query('vehicleId') vehicleId?: string,
    @Query('type') type?: ComplianceType,
  ) {
    return this.complianceService.findAll({ vehicleId, type });
  }

  @Get('alerts')
  @ApiOperation({ summary: 'List overdue / due-soon compliance & expiry alerts' })
  getAlerts() {
    return this.complianceService.getAlerts();
  }

  @Get(':id')
  @ApiOperation({ summary: 'Get a compliance record by ID' })
  findOne(@Param('id') id: string) {
    return this.complianceService.findById(id);
  }

  @Patch(':id')
  @ApiOperation({ summary: 'Update a compliance record' })
  update(@Param('id') id: string, @Body() dto: UpdateComplianceRecordDto) {
    return this.complianceService.update(id, dto);
  }

  @Delete(':id')
  @ApiOperation({ summary: 'Soft-delete a compliance record' })
  remove(@Param('id') id: string) {
    return this.complianceService.remove(id);
  }
}
