import * as tables from '../server/database/schema'
import { createInsertSchema, createSelectSchema } from 'drizzle-zod'

// Drizzle-inferred record types
export type User = typeof tables.user.$inferSelect
export type InsertUser = typeof tables.user.$inferInsert

// Extended user type for impersonation (runtime augmentation)
export type ExtendedUser = User & {
  _impersonated?: boolean
}

export type OAuthAccount = typeof tables.account.$inferSelect
export type InsertOAuthAccount = typeof tables.account.$inferInsert

export type Product = typeof tables.products.$inferSelect
export type InsertProduct = typeof tables.products.$inferInsert

export type Price = typeof tables.prices.$inferSelect
export type InsertPrice = typeof tables.prices.$inferInsert

export type Customer = typeof tables.customers.$inferSelect
export type InsertCustomer = typeof tables.customers.$inferInsert

export type Subscription = typeof tables.subscriptions.$inferSelect
export type InsertSubscription = typeof tables.subscriptions.$inferInsert

// Admin/feedback tables
export type Feedback = typeof tables.feedback.$inferSelect
export type InsertFeedback = typeof tables.feedback.$inferInsert
export type Subscriber = typeof tables.subscribers.$inferSelect
export type InsertSubscriber = typeof tables.subscribers.$inferInsert

// Helper relation shapes commonly used in UI (e.g. billing page)
export type PriceWithProduct = Price & { product: Product }

// Zod schemas for runtime validation where needed
export const insertUserSchema = createInsertSchema(tables.user)
export const selectUserSchema = createSelectSchema(tables.user)

export const insertProductSchema = createInsertSchema(tables.products)
export const selectProductSchema = createSelectSchema(tables.products)

export const insertPriceSchema = createInsertSchema(tables.prices)
export const selectPriceSchema = createSelectSchema(tables.prices)

export const insertCustomerSchema = createInsertSchema(tables.customers)
export const selectCustomerSchema = createSelectSchema(tables.customers)

export const insertSubscriptionSchema = createInsertSchema(tables.subscriptions)
export const selectSubscriptionSchema = createSelectSchema(tables.subscriptions)
