import { IsOptional, IsString, IsDateString, IsInt, Min } from 'class-validator';
import { Type } from 'class-transformer';

/**
 * Parameters for importing attendance data from DingTalk.
 * Mirrors `dws attendance check result` flags.
 */
export class DingTalkImportDto {
  /** Start date (YYYY-MM-DD). Defaults to today when omitted. */
  @IsOptional()
  @IsDateString()
  start?: string;

  /** End date (YYYY-MM-DD). Defaults to start/today when omitted. */
  @IsOptional()
  @IsDateString()
  end?: string;

  /** Target class. Required for non-super-admin users. */
  @IsOptional()
  @IsInt()
  @Min(1)
  @Type(() => Number)
  classId?: number;

  /** Comma-separated DingTalk user IDs. Super-admin override only. */
  @IsOptional()
  @IsString()
  users?: string;
}

/**
 * Progress event emitted via SSE stream during import.
 */
export interface ImportProgressEvent {
  phase: 'fetching' | 'parsing' | 'saving' | 'matching' | 'complete' | 'error';
  /** Current progress count */
  current: number;
  /** Total expected (estimated, may change) */
  total: number;
  /** Human-readable message */
  message: string;
  /** Error message (only when phase === 'error') */
  error?: string;
  /** ID of the user who triggered the import (undefined for non-HTTP callers) */
  userId?: number;
}

/**
 * Result returned after import completes.
 */
export interface ImportResult {
  success: boolean;
  imported: number;
  skipped: number;
  matched: number;
  errors: string[];
  /** Duration in ms */
  duration: number;
}
