import {
  IsBoolean,
  IsEnum,
  IsInt,
  IsNumber,
  IsOptional,
  IsString,
  MinLength,
} from "class-validator";
import { Currency, ServiceKind, StatementDocumentStatus } from "@jorgecuadros/database";

export class CreateStatementBatchDto {
  @IsEnum(ServiceKind) serviceKind!: ServiceKind;
  @IsOptional() @IsString() label?: string;
}

/** Staff correction of one document's extracted fields or its match. */
export class ReviewDocumentDto {
  @IsOptional() @IsString() accountRef?: string;
  @IsOptional() @IsNumber() amount?: number;
  @IsOptional() @IsString() period?: string;
  @IsOptional() @IsString() dueDate?: string;
  @IsOptional() @IsString() matchedPropertyServiceId?: string;
  @IsOptional() @IsString() matchedCustomerId?: string;
  // Restricted to the review-reachable states: a client cannot declare a
  // document POSTED, because only a successful ledger write may do that.
  @IsOptional()
  @IsEnum(StatementDocumentStatus)
  status?: Extract<StatementDocumentStatus, "MATCHED" | "NEEDS_REVIEW" | "CONFIRMED">;
}

/**
 * Post a batch's confirmed documents. The check-level fields are shared by
 * every line, exactly as on the manual batch-capture screen — an OCR batch is
 * still "these receipts, paid by this check".
 */
export class ConfirmBatchDto {
  @IsString() @MinLength(1) checkNumber!: string;
  @IsString() @MinLength(1) transactionDate!: string;
  @IsOptional() @IsEnum(Currency) currency?: Currency;
  /** Overrides the concept derived from the batch's service kind. */
  @IsOptional() @IsString() typeId?: string;
  /** Post as outstanding (sin fondos) — captured but not yet funded. */
  @IsOptional() @IsBoolean() outstanding?: boolean;
  /** Also post documents a reviewer explicitly marked CONFIRMED. */
  @IsOptional() @IsBoolean() includeReviewed?: boolean;
}

export class ListBatchesQuery {
  @IsOptional() @IsInt() page?: number;
  @IsOptional() @IsInt() pageSize?: number;
}
