import { createZodDto } from 'nestjs-zod';
import { z } from 'zod';
import {
  ExchangeCodeRequestSchema,
  ExchangeCodeResponseSchema,
  MockLoginRequestSchema,
  MockLoginResponseSchema,
  MockUsersResponseSchema,
  RefreshTokenRequestSchema,
  RefreshTokenResponseSchema,
  SessionResponseSchema,
  TokenExchangeRequestSchema,
  TokenExchangeResponseSchema,
} from '@pac/types';

export class TokenExchangeRequestDto extends createZodDto(TokenExchangeRequestSchema) {}
export class TokenExchangeResponseDto extends createZodDto(TokenExchangeResponseSchema) {}
export class ExchangeCodeRequestDto extends createZodDto(ExchangeCodeRequestSchema) {}
export class ExchangeCodeResponseDto extends createZodDto(ExchangeCodeResponseSchema) {}
export class RefreshTokenRequestDto extends createZodDto(RefreshTokenRequestSchema) {}
export class RefreshTokenResponseDto extends createZodDto(RefreshTokenResponseSchema) {}
export class MockLoginRequestDto extends createZodDto(MockLoginRequestSchema) {}
export class MockLoginResponseDto extends createZodDto(MockLoginResponseSchema) {}
export class MockUsersResponseDto extends createZodDto(MockUsersResponseSchema) {}
export class SessionResponseDto extends createZodDto(SessionResponseSchema) {}

/**
 * 前端 bootstrap 诊断信标(嵌入首开鉴权路径定位用)。
 * 全字段可选 + passthrough:只为落一行服务端日志,不做业务校验,尽量不因字段挑剔而丢诊断。
 */
export const ClientDiagRequestSchema = z
  .object({
    phase: z.string().max(40).optional(),
    ev: z.string().max(40).optional(),
    hadCode: z.boolean().optional(),
    codeTag: z.string().max(16).nullable().optional(),
    storedAccess: z.boolean().optional(),
    storedRefresh: z.boolean().optional(),
    storedAccessValid: z.boolean().optional(),
    err: z.string().max(120).nullable().optional(),
    // 环境/存储探针
    storageWritable: z.boolean().optional(),
    isEmbedded: z.boolean().optional(),
    hostOrigin: z.string().max(200).nullable().optional(),
    isReload: z.boolean().optional(),
    ua: z.string().max(200).optional(),
  })
  .passthrough();
export class ClientDiagRequestDto extends createZodDto(ClientDiagRequestSchema) {}
