import { createZodDto } from 'nestjs-zod';
import { z } from 'zod';
import {
  ListHostsResponseSchema,
  HostSummarySchema,
  HostDetailSchema,
  HostStatsSchema,
  RotatePushSecretResponseSchema,
  RotateCallbackSecretResponseSchema,
  RotateSecretResponseSchema,
  RemovePushSecretRequestSchema,
  RemovePushSecretResponseSchema,
  UpdateHostRequestSchema,
  AiInvocationListQuerySchema,
  AiInvocationDetailSchema,
  AiInvocationStatsSchema,
  ListAiInvocationsResponseSchema,
} from '@pac/types';

export class ListHostsResponseDto extends createZodDto(ListHostsResponseSchema) {}
export class HostSummaryDto extends createZodDto(HostSummarySchema) {}
export class HostDetailDto extends createZodDto(HostDetailSchema) {}
export class HostStatsDto extends createZodDto(HostStatsSchema) {}
export class UpdateHostRequestDto extends createZodDto(UpdateHostRequestSchema) {}
export class RotateSecretResponseDto extends createZodDto(RotateSecretResponseSchema) {}
export class RotatePushSecretResponseDto extends createZodDto(RotatePushSecretResponseSchema) {}
export class RotateCallbackSecretResponseDto extends createZodDto(RotateCallbackSecretResponseSchema) {}
export class RemovePushSecretRequestDto extends createZodDto(RemovePushSecretRequestSchema) {}
export class RemovePushSecretResponseDto extends createZodDto(RemovePushSecretResponseSchema) {}

// AI Invocations
export class AiInvocationListQueryDto extends createZodDto(AiInvocationListQuerySchema) {}
export class AiInvocationDetailDto extends createZodDto(AiInvocationDetailSchema) {}
export class AiInvocationStatsDto extends createZodDto(AiInvocationStatsSchema) {}
export class ListAiInvocationsResponseDto extends createZodDto(ListAiInvocationsResponseSchema) {}

// Cold-import 网页上传(host-self)
const ColdImportUploadResponseSchema = z.object({ jobId: z.string() });
export class ColdImportUploadResponseDto extends createZodDto(ColdImportUploadResponseSchema) {}

// 进度:BullMQ job 状态 + 完成时的 ImportRunResult(含 totals);job 已清理/不存在 → state='not_found'
const ColdImportStatusSchema = z.object({
  state: z.string(),
  result: z.any().nullable(),
  failedReason: z.string().nullable(),
  // 运行中的真实进度(cohortDone/cohortTotal 批次);非运行态或 dryRun 为 null
  progress: z.object({ done: z.number(), total: z.number() }).nullable(),
});
export class ColdImportStatusDto extends createZodDto(ColdImportStatusSchema) {}
