import {z} from 'zod'

export const RequestMagicLinkSchema = z.object({
  email: z
    .email()
    .max(254)
    .transform((s) => s.trim().toLowerCase()),
})

// randomBytes(32).toString('base64url') → exactly 43 chars of [A-Za-z0-9_-]
export const VerifyTokenSchema = z.object({
  token: z.string().regex(/^[A-Za-z0-9_-]{43}$/),
})

export const ExchangeCodeSchema = z.object({
  code: z.string().regex(/^[A-Za-z0-9_-]{43}$/),
})

export const PublicUserSchema = z.object({
  id: z.uuid(),
  email: z.email(),
  handle: z.string(),
  avatarUrl: z.url().nullable(),
  createdAt: z.iso.datetime(),
})

export const MeResponseSchema = z.object({
  user: PublicUserSchema,
})

export type RequestMagicLinkInput = z.infer<
  typeof RequestMagicLinkSchema
>
export type PublicUser = z.infer<typeof PublicUserSchema>
