import { z } from 'zod';
import { ROLE_NAMES } from '../permissions';

export const AuthUserSchema = z.object({
  id: z.uuid(),
  email: z.email(),
  displayName: z.string(),
  role: z.object({ id: z.uuid(), name: z.enum(ROLE_NAMES) }),
  isDemo: z.boolean(),
});
export type AuthUser = z.infer<typeof AuthUserSchema>;

export const LoginRequestSchema = z.object({
  email: z.email(),
  password: z.string().min(1),
});
export type LoginRequest = z.infer<typeof LoginRequestSchema>;

export const AuthResponseSchema = z.object({
  accessToken: z.string(),
  user: AuthUserSchema,
});
export type AuthResponse = z.infer<typeof AuthResponseSchema>;

/** ADR-002 — jamais de secret dans cette liste. */
export const DemoAccountSchema = z.object({
  id: z.uuid(),
  displayName: z.string(),
  roleName: z.enum(ROLE_NAMES),
  initials: z.string().min(1).max(3),
});
export type DemoAccount = z.infer<typeof DemoAccountSchema>;

export const DemoAccountsResponseSchema = z.object({
  accounts: z.array(DemoAccountSchema),
});
export type DemoAccountsResponse = z.infer<typeof DemoAccountsResponseSchema>;

export const DemoLoginRequestSchema = z.object({
  userId: z.uuid(),
});
export type DemoLoginRequest = z.infer<typeof DemoLoginRequestSchema>;
