import { bigint, integer, pgTable, text, timestamp, uuid } from 'drizzle-orm/pg-core'

export const cart = pgTable('cart', {
  id: uuid('id').primaryKey().defaultRandom(),
  currency: text('currency').notNull(),
  userId: text('user_id'),
  createdAt: timestamp('created_at', { withTimezone: true, precision: 3 }).notNull().defaultNow(),
  updatedAt: timestamp('updated_at', { withTimezone: true, precision: 3 }).notNull().defaultNow(),
})

export const cartLine = pgTable('cart_line', {
  id: uuid('id').primaryKey().defaultRandom(),
  cartId: uuid('cart_id').notNull(),
  variantId: uuid('variant_id').notNull(),
  qty: integer('qty').notNull(),
  amount: bigint('amount', { mode: 'bigint' }).notNull(),
  currency: text('currency').notNull(),
  priceMode: text('price_mode').$type<'inclusive' | 'exclusive'>().notNull(),
  vendorId: text('vendor_id'),
})

export const cartSchema = {
  cart,
  cartLine,
}

export type CartSchema = typeof cartSchema
