import { z } from "zod";

export const registerInputSchema = z.object({
  email: z.string().trim().toLowerCase().max(255).pipe(z.email()),
  password: z.string().min(10, "Lösenordet måste vara minst 10 tecken").max(200),
  displayName: z.string().min(1).max(80).trim(),
  locale: z.string().min(2).max(10).default("sv-SE"),
});
export type RegisterInput = z.infer<typeof registerInputSchema>;

export const loginInputSchema = z.object({
  email: z.string().trim().toLowerCase().pipe(z.email()),
  password: z.string().min(1).max(200),
});
export type LoginInput = z.infer<typeof loginInputSchema>;

export const refreshInputSchema = z.object({
  refreshToken: z.string().min(10),
});
export type RefreshInput = z.infer<typeof refreshInputSchema>;

export const authTokensSchema = z.object({
  accessToken: z.string(),
  refreshToken: z.string(),
  accessTokenExpiresIn: z.number(),
});
export type AuthTokens = z.infer<typeof authTokensSchema>;

export const changePasswordInputSchema = z.object({
  currentPassword: z.string().min(1),
  newPassword: z.string().min(10).max(200),
});
export type ChangePasswordInput = z.infer<typeof changePasswordInputSchema>;

export const forgotPasswordInputSchema = z.object({
  email: z.string().trim().toLowerCase().pipe(z.email()),
});
export type ForgotPasswordInput = z.infer<typeof forgotPasswordInputSchema>;

export const resetPasswordInputSchema = z.object({
  token: z.string().min(32).max(200),
  newPassword: z.string().min(10).max(200),
});
export type ResetPasswordInput = z.infer<typeof resetPasswordInputSchema>;

export const verifyEmailInputSchema = z.object({
  token: z.string().min(32).max(200),
});
export type VerifyEmailInput = z.infer<typeof verifyEmailInputSchema>;

export const totpVerifyInputSchema = z.object({
  preAuthToken: z.string().min(10),
  code: z
    .string()
    .trim()
    .regex(/^\d{6}$/),
});
export type TotpVerifyInput = z.infer<typeof totpVerifyInputSchema>;

export const totpCodeInputSchema = z.object({
  code: z
    .string()
    .trim()
    .regex(/^\d{6}$/),
});
export type TotpCodeInput = z.infer<typeof totpCodeInputSchema>;
