import {
  IsString, IsOptional, IsArray, IsNumber, IsBoolean,
  ValidateNested, IsIn, Min, ArrayMinSize,
} from 'class-validator'
import { Type } from 'class-transformer'

export class DirectorDto {
  @IsOptional()
  @IsString()
  uid?: string

  @IsString()
  nameEn: string

  @IsString()
  nameTh: string

  @IsString()
  email: string

  @IsOptional()
  @IsString()
  lineId?: string

  @IsString()
  @IsIn(['director', 'chairman'])
  role: 'director' | 'chairman'
}

export class ShareholderDto {
  @IsOptional()
  @IsString()
  uid?: string

  @IsString()
  entityNameEn: string

  @IsString()
  entityNameTh: string

  @IsNumber()
  @Min(1)
  shareCount: number

  @IsString()
  contactEmail: string

  @IsOptional()
  @IsString()
  lineId?: string

  @IsOptional()
  @IsString()
  proxyToUid?: string
}

export class MeetingDto {
  @IsOptional()
  @IsString()
  date?: string   // ISO date string e.g. "2026-04-15"

  @IsOptional()
  @IsString()
  time?: string   // e.g. "10:00"

  @IsOptional()
  @IsString()
  venue?: string
}

export class CreateAnnualComplianceDto {
  /** The client folder this matter belongs to */
  @IsString()
  clientFolderId: string

  /** The responsible attorney */
  @IsString()
  responsibleAttorney: string

  // ── Company identity ────────────────────────────────────────────────────

  @IsString()
  companyNameEn: string

  @IsString()
  companyNameTh: string

  @IsOptional()
  @IsString()
  companyRegNumber?: string

  /** e.g. "2025" */
  @IsString()
  fiscalYear: string

  /** ISO date string e.g. "2025-12-31" — drives all deadline calculations */
  @IsString()
  yearEndDate: string

  @IsOptional()
  @IsString()
  registeredAddressEn?: string

  @IsOptional()
  @IsString()
  registeredAddressTh?: string

  // ── People ──────────────────────────────────────────────────────────────

  @IsArray()
  @ArrayMinSize(1)
  @ValidateNested({ each: true })
  @Type(() => DirectorDto)
  directors: DirectorDto[]

  @IsArray()
  @ArrayMinSize(1)
  @ValidateNested({ each: true })
  @Type(() => ShareholderDto)
  shareholders: ShareholderDto[]

  // ── Meetings ────────────────────────────────────────────────────────────

  @IsOptional()
  @ValidateNested()
  @Type(() => MeetingDto)
  bodMeeting?: MeetingDto

  @IsOptional()
  @ValidateNested()
  @Type(() => MeetingDto)
  agmMeeting?: MeetingDto

  // ── Auditor ─────────────────────────────────────────────────────────────

  @IsOptional()
  @IsString()
  auditorName?: string

  @IsOptional()
  @IsNumber()
  auditorFeeThb?: number

  // ── Fee ─────────────────────────────────────────────────────────────────

  @IsOptional()
  @IsNumber()
  feeThb?: number

  @IsOptional()
  @IsBoolean()
  vatIncluded?: boolean

  @IsOptional()
  @IsString()
  notes?: string
}

export class UpdateDocumentStatusDto {
  @IsString()
  @IsIn(['draft', 'sent', 'signed', 'returned'])
  status: 'draft' | 'sent' | 'signed' | 'returned'
}
