import { z } from "zod/v4";
import { Uuid } from "./domain.js";
import { OmniFlowSessionSummarySchema } from "./omni-flow-session.js";

/**
 * Identity == a Chrome persona owned by the org. Holds the primary
 * email/password the dp-worker uses for Gmail / Google flows, plus an
 * optional egress proxy. Per-platform sub-accounts (X / YouTube / Reddit)
 * live in the `social_accounts` table and inherit `persona_text` by default.
 */

export const IdentityRow = z.object({
  id: Uuid,
  name: z.string(),
  email: z.string().email(),
  password: z.string().nullable(),
  proxy_id: Uuid.nullable(),
  persona_text: z.string(),
  bound_worker_id: Uuid.optional(),
  bound_worker_name: z.string().optional(),
  created_at: z.string().datetime(),
  updated_at: z.string().datetime(),
});
export type IdentityRow = z.infer<typeof IdentityRow>;

export const CreateIdentityBody = z.object({
  name: z.string().min(1).max(120),
  email: z.string().email(),
  password: z.string().min(1).nullable().optional(),
  proxy_id: Uuid.nullable().optional(),
  persona_text: z.string().default(""),
  /** Optional UI-provided preview for create-time session/proxy validation. */
  session_preview: OmniFlowSessionSummarySchema.optional(),
});
export type CreateIdentityBody = z.infer<typeof CreateIdentityBody>;

export const PatchIdentityBody = CreateIdentityBody.partial();
export type PatchIdentityBody = z.infer<typeof PatchIdentityBody>;
