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

export const stackEnum = pgEnum('stack', [
  'data_analytics',
  'digital_marketing',
  'web_development',
  'product_design',
  'ai_automation',
]);

export const genderEnum = pgEnum('gender', ['male', 'female', 'prefer_not_to_say']);

export const educationEnum = pgEnum('education_level', [
  'secondary',
  'undergraduate',
  'graduate',
  'postgraduate',
  'other',
]);

export const ageRangeEnum = pgEnum('age_range', [
  'under_18',
  '18_25',
  '26_30',
  '31_35',
  '36_plus',
]);

export const userRoleEnum = pgEnum('user_role', ['user', 'admin']);

export const registrations = pgTable('registrations', {
  id: uuid('id').defaultRandom().primaryKey(),
  fullName: text('full_name').notNull(),
  email: text('email').notNull().unique(),
  phone: text('phone').notNull(),
  gender: genderEnum('gender').notNull(),
  ageRange: ageRangeEnum('age_range').notNull(),
  educationLevel: educationEnum('education_level').notNull(),
  institution: text('institution').notNull(),
  stack: stackEnum('stack').notNull(),
  motivation: text('motivation').notNull(),
  heardFrom: text('heard_from').notNull(),
  referralCode: text('referral_code'),          // nullable — optional field
  createdAt: timestamp('created_at').defaultNow().notNull(),
});

export const profiles = pgTable('profiles', {
  id: uuid('id').primaryKey(), // references auth.users(id)
  email: text('email').notNull().unique(),
  fullName: text('full_name'),
  role: userRoleEnum('role').notNull().default('user'),
  createdAt: timestamp('created_at').defaultNow().notNull(),
  updatedAt: timestamp('updated_at').defaultNow().notNull(),
});

export type Registration = typeof registrations.$inferSelect;
export type NewRegistration = typeof registrations.$inferInsert;
export type Profile = typeof profiles.$inferSelect;
export type NewProfile = typeof profiles.$inferInsert;