import { z } from "zod";

export const TransactionScopeSchema = z.enum(["household", "private", "child"]);

export const CreateTransactionSchema = z.object({
  amount: z.number().positive("Betrag muss positiv sein"),
  type: z.enum(["income", "expense"]),
  scope: TransactionScopeSchema.default("household"),
  childId: z.string().min(1).optional(),
  categoryId: z.string().min(1).optional(),
  description: z.string().max(255).optional(),
  merchant: z.string().max(255).optional(),
  date: z.string().datetime({ offset: true }),
  isFixed: z.boolean().default(false),
});

export const UpdateTransactionSchema = CreateTransactionSchema.partial();

export const TransactionFiltersSchema = z.object({
  categoryId: z.string().optional(),
  type: z.enum(["income", "expense"]).optional(),
  scope: TransactionScopeSchema.optional(),
  childId: z.string().optional(),
  from: z.string().datetime({ offset: true }).optional(),
  to: z.string().datetime({ offset: true }).optional(),
  limit: z.coerce.number().min(1).max(100).default(50),
  offset: z.coerce.number().min(0).default(0),
});

export type CreateTransactionInput = z.infer<typeof CreateTransactionSchema>;
export type UpdateTransactionInput = z.infer<typeof UpdateTransactionSchema>;
export type TransactionFilters = z.infer<typeof TransactionFiltersSchema>;
