import { z } from "zod";

export const financeEntrySchema = z.object({
  type: z.enum(["income", "expense", "debt", "receivable"]),
  amount: z
    .union([z.number(), z.string()])
    .transform((v) => (typeof v === "string" ? Number(v.replace(",", ".")) : v))
    .pipe(z.number().positive("Tutar 0'dan büyük olmalı.")),
  date: z.string().min(1, "Tarih zorunlu."),
  description: z.string().trim().max(1000).optional().transform((v) => (v ? v : undefined)),
  customerId: z.string().optional().transform((v) => (v ? v : undefined)),
  invoiceId: z.string().optional().transform((v) => (v ? v : undefined)),
  paymentMethod: z
    .enum(["cash", "transfer", "card", "check", "other"])
    .optional()
    .transform((v) => v || undefined),
  bankAccountId: z.string().optional().transform((v) => (v ? v : undefined)),
  scope: z.enum(["company", "personal"]).optional().default("company"),
});

export type FinanceEntryInput = z.infer<typeof financeEntrySchema>;
