import { z } from "zod";

export const registerSchema = z.object({
  firstName: z.string().min(1).max(80),
  email: z.string().email(),
  password: z.string().min(8).max(72),
  preferredLanguage: z.enum(["en", "pl"])
});
export type RegisterInput = z.infer<typeof registerSchema>;

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

export const forgotPasswordSchema = z.object({
  email: z.string().email()
});

export const resetPasswordSchema = z.object({
  password: z.string().min(8).max(72)
});

export const onboardingSchema = z.object({
  goal: z.enum(["save", "control", "organize", "subscriptions", "everything"]),
  monthlyIncome: z.coerce.number().min(0),
  currency: z.enum(["PLN", "EUR", "USD", "GBP"]),
  savingsGoal: z.coerce.number().min(0).optional(),
  preferredLanguage: z.enum(["en", "pl"])
});
export type OnboardingInput = z.infer<typeof onboardingSchema>;

export const expenseSchema = z.object({
  amount: z.coerce.number().positive(),
  currency: z.enum(["PLN", "EUR", "USD", "GBP"]),
  category: z.enum([
    "food",
    "housing",
    "transport",
    "shopping",
    "entertainment",
    "health",
    "bills",
    "subscriptions",
    "travel",
    "education",
    "other"
  ]),
  description: z.string().max(280).optional(),
  paymentMethod: z.enum(["card", "cash", "transfer", "blik"]),
  occurredOn: z.string() // ISO date
});
export type ExpenseInput = z.infer<typeof expenseSchema>;

export const budgetCategorySchema = z.object({
  category: z.string().min(1),
  amount: z.coerce.number().min(0)
});
export type BudgetCategoryInput = z.infer<typeof budgetCategorySchema>;

export const goalSchema = z.object({
  name: z.string().min(1).max(80),
  targetAmount: z.coerce.number().positive(),
  currentAmount: z.coerce.number().min(0).default(0),
  deadline: z.string().optional()
});
export type GoalInput = z.infer<typeof goalSchema>;

export const goalContributionSchema = z.object({
  amount: z.coerce.number().positive()
});

export const subscriptionSchema = z.object({
  name: z.string().min(1).max(80),
  price: z.coerce.number().min(0),
  currency: z.enum(["PLN", "EUR", "USD", "GBP"]),
  billingCycle: z.enum(["monthly", "yearly"]),
  category: z.string().optional(),
  nextPaymentDate: z.string()
});
export type SubscriptionInput = z.infer<typeof subscriptionSchema>;

export const taskSchema = z.object({
  title: z.string().min(1).max(200),
  priority: z.enum(["low", "medium", "high"]),
  dueDate: z.string().optional()
});
export type TaskInput = z.infer<typeof taskSchema>;

export const settingsProfileSchema = z.object({
  firstName: z.string().min(1).max(80),
  currency: z.enum(["PLN", "EUR", "USD", "GBP"]),
  preferredLanguage: z.enum(["en", "pl"])
});

export const settingsNotificationsSchema = z.object({
  emailNotifications: z.boolean(),
  budgetAlerts: z.boolean(),
  subscriptionReminders: z.boolean(),
  goalUpdates: z.boolean()
});
