import {
  pgTable,
  text,
  jsonb,
  timestamp,
  uuid
} from 'drizzle-orm/pg-core'
import { user } from './auth'
import { relations } from 'drizzle-orm'

export const subscribers = pgTable('subscribers', {
  id: uuid('id').primaryKey().defaultRandom(),
  email: text('email').notNull().unique(),
  referrer: text('referrer'),
  meta: jsonb('meta'),
  createdAt: timestamp('created_at').defaultNow(),
  updatedAt: timestamp('updated_at').defaultNow()
})

export const feedback = pgTable('feedback', {
  id: uuid('id').primaryKey().defaultRandom(),
  userId: text('user_id')
    .notNull()
    .references(() => user.id, { onDelete: 'cascade' }),
  message: text('message').notNull(),
  status: text('status').notNull().default('pending'),
  reply: text('reply'),
  meta: jsonb('meta'),
  createdAt: timestamp('created_at').defaultNow()
})

export const feedbackRelations = relations(feedback, ({ one }) => ({
  user: one(user, {
    fields: [feedback.userId],
    references: [user.id]
  })
}))
