import { pgTable, serial, text, numeric, timestamp } from "drizzle-orm/pg-core";
import { createInsertSchema } from "drizzle-zod";
import { z } from "zod/v4";

export const creditorsTable = pgTable("creditors", {
  id: serial("id").primaryKey(),
  name: text("name").notNull(),
  phone: text("phone"),
  creditorType: text("creditor_type"),
  notes: text("notes"),
  balance: numeric("balance", { precision: 15, scale: 2 }).default("0").notNull(),
  createdAt: timestamp("created_at").defaultNow().notNull(),
});

export const insertCreditorSchema = createInsertSchema(creditorsTable).omit({ id: true, createdAt: true, balance: true });
export type InsertCreditor = z.infer<typeof insertCreditorSchema>;
export type Creditor = typeof creditorsTable.$inferSelect;
