import {
  Body, Controller, Get, Param, Post, Patch, Query,
} from '@nestjs/common'
import { AnnualComplianceService } from './annual-compliance.service'
import { CreateAnnualComplianceDto, UpdateDocumentStatusDto } from './dto/create-annual-compliance.dto'

@Controller('annual-compliance')
export class AnnualComplianceController {
  constructor(private readonly svc: AnnualComplianceService) {}

  /** Dashboard: all annual compliance matters with urgency info */
  @Get('dashboard')
  dashboard() {
    return this.svc.dashboard()
  }

  /** All annual compliance matters for a specific client folder */
  @Get('client/:clientFolderId')
  findByClient(@Param('clientFolderId') clientFolderId: string) {
    return this.svc.findByClient(clientFolderId)
  }

  /** Single matter detail */
  @Get(':matterId')
  findOne(@Param('matterId') matterId: string) {
    return this.svc.findOne(matterId)
  }

  /**
   * Create a new annual compliance matter.
   * Automatically generates deadline proposals for all 4 statutory obligations.
   */
  @Post()
  create(@Body() dto: CreateAnnualComplianceDto) {
    return this.svc.create(dto)
  }

  /**
   * Generate the full document set for a matter.
   * Produces all bilingual EN/TH PDFs: BOD package + AGM package.
   * Documents are stored on disk and logged in form_generation_logs.
   */
  @Post(':matterId/generate-documents')
  generateDocuments(
    @Param('matterId') matterId: string,
    @Query('by') generatedBy?: string,
  ) {
    return this.svc.generateAllDocuments(matterId, generatedBy)
  }

  /**
   * Update document signature status.
   * Status flow: draft → sent → signed → returned
   */
  @Patch(':matterId/documents/:docUid/status')
  updateDocumentStatus(
    @Param('matterId') matterId: string,
    @Param('docUid') docUid: string,
    @Body() dto: UpdateDocumentStatusDto,
  ) {
    return this.svc.updateDocumentStatus(matterId, docUid, dto.status)
  }

  /** Statutory deadlines for a matter */
  @Get(':matterId/deadlines')
  getDeadlines(@Param('matterId') matterId: string) {
    return this.svc.getDeadlines(matterId)
  }
}
