import { boolean, char, doublePrecision, integer, jsonb, pgEnum, pgTable, serial, text, timestamp, uuid, varchar } from 'drizzle-orm/pg-core';
import { AreasServed, LicensedIn } from '../models/db.model';
export const PG_CONNECTION = 'PG_CONNECTION';
export const genderEnum = pgEnum('gender', ['male', 'female']);
export const customerTypeEnum = pgEnum('customerType', ['buyer', 'professional']);
export const customerSubTypeEnum = pgEnum('customerSubType', ['broker', 'cpa', 'attorney', 'titleCompany', 'surveyor', 'appraiser']);
export const listingsCategoryEnum = pgEnum('listingsCategory', ['commercialProperty', 'business']);

export const users = pgTable('users', {
  id: uuid('id').primaryKey().defaultRandom().notNull(),
  firstname: varchar('firstname', { length: 255 }).notNull(),
  lastname: varchar('lastname', { length: 255 }).notNull(),
  email: varchar('email', { length: 255 }).notNull().unique(),
  phoneNumber: varchar('phoneNumber', { length: 255 }),
  description: text('description'),
  companyName: varchar('companyName', { length: 255 }),
  companyOverview: text('companyOverview'),
  companyWebsite: varchar('companyWebsite', { length: 255 }),
  city: varchar('city', { length: 255 }),
  state: char('state', { length: 2 }),
  offeredServices: text('offeredServices'),
  areasServed: jsonb('areasServed').$type<AreasServed[]>(),
  hasProfile: boolean('hasProfile'),
  hasCompanyLogo: boolean('hasCompanyLogo'),
  licensedIn: jsonb('licensedIn').$type<LicensedIn[]>(),
  gender: genderEnum('gender'),
  customerType: customerTypeEnum('customerType'),
  customerSubType: customerSubTypeEnum('customerSubType'),
  created: timestamp('created'),
  updated: timestamp('updated'),
  latitude: doublePrecision('latitude'),
  longitude: doublePrecision('longitude'),
  // embedding: vector('embedding', { dimensions: 1536 }),
});

export const businesses = pgTable('businesses', {
  id: uuid('id').primaryKey().defaultRandom().notNull(),
  email: varchar('email', { length: 255 }).references(() => users.email),
  type: varchar('type', { length: 255 }),
  title: varchar('title', { length: 255 }),
  description: text('description'),
  city: varchar('city', { length: 255 }),
  state: char('state', { length: 2 }),
  zipCode: integer('zipCode'),
  county: varchar('county', { length: 255 }),
  price: doublePrecision('price'),
  favoritesForUser: varchar('favoritesForUser', { length: 30 }).array(),
  draft: boolean('draft'),
  listingsCategory: listingsCategoryEnum('listingsCategory'), //varchar('listingsCategory', { length: 255 }),
  realEstateIncluded: boolean('realEstateIncluded'),
  leasedLocation: boolean('leasedLocation'),
  franchiseResale: boolean('franchiseResale'),
  salesRevenue: doublePrecision('salesRevenue'),
  cashFlow: doublePrecision('cashFlow'),
  supportAndTraining: text('supportAndTraining'),
  employees: integer('employees'),
  established: integer('established'),
  internalListingNumber: integer('internalListingNumber'),
  reasonForSale: varchar('reasonForSale', { length: 255 }),
  brokerLicencing: varchar('brokerLicencing', { length: 255 }),
  internals: text('internals'),
  imageName: varchar('imageName', { length: 200 }),
  created: timestamp('created'),
  updated: timestamp('updated'),
  visits: integer('visits'),
  lastVisit: timestamp('lastVisit'),
  latitude: doublePrecision('latitude'),
  longitude: doublePrecision('longitude'),
  // embedding: vector('embedding', { dimensions: 1536 }),
});

export const commercials = pgTable('commercials', {
  id: uuid('id').primaryKey().defaultRandom().notNull(),
  serialId: serial('serialId'),
  email: varchar('email', { length: 255 }).references(() => users.email),
  type: varchar('type', { length: 255 }),
  title: varchar('title', { length: 255 }),
  description: text('description'),
  city: varchar('city', { length: 255 }),
  state: char('state', { length: 2 }),
  price: doublePrecision('price'),
  favoritesForUser: varchar('favoritesForUser', { length: 30 }).array(),
  listingsCategory: listingsCategoryEnum('listingsCategory'), //listingsCategory: varchar('listingsCategory', { length: 255 }),
  draft: boolean('draft'),
  zipCode: integer('zipCode'),
  county: varchar('county', { length: 255 }),
  imageOrder: varchar('imageOrder', { length: 200 }).array(),
  imagePath: varchar('imagePath', { length: 200 }),
  created: timestamp('created'),
  updated: timestamp('updated'),
  visits: integer('visits'),
  lastVisit: timestamp('lastVisit'),
  latitude: doublePrecision('latitude'),
  longitude: doublePrecision('longitude'),
  // embedding: vector('embedding', { dimensions: 1536 }),
});
