import { z } from "zod";

export const bankAccountSchema = z.object({
  bankName: z.string().trim().min(1, "Banka adı zorunlu.").max(100),
  accountName: z.string().trim().min(1, "Hesap adı zorunlu.").max(100),
  iban: z
    .string()
    .trim()
    .max(50)
    .optional()
    .transform((v) => (v ? v.replace(/\s+/g, "").toUpperCase() : undefined)),
  openingBalance: z
    .union([z.number(), z.string()])
    .optional()
    .transform((v) => {
      if (v === undefined || v === "") return 0;
      const n = typeof v === "string" ? Number(v.replace(",", ".")) : v;
      return Number.isFinite(n) ? n : 0;
    }),
  notes: z
    .string()
    .trim()
    .max(500)
    .optional()
    .transform((v) => (v ? v : undefined)),
  scope: z.enum(["company", "personal"]).optional().default("company"),
});

export type BankAccountInput = z.infer<typeof bankAccountSchema>;
