DO $$ BEGIN
 CREATE TYPE "public"."customerSubType" AS ENUM('broker', 'cpa', 'attorney', 'titleCompany', 'surveyor', 'appraiser');
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
 CREATE TYPE "public"."customerType" AS ENUM('buyer', 'professional');
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
 CREATE TYPE "public"."gender" AS ENUM('male', 'female');
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
 CREATE TYPE "public"."listingsCategory" AS ENUM('commercialProperty', 'business');
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "businesses" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"email" varchar(255),
	"type" varchar(255),
	"title" varchar(255),
	"description" text,
	"city" varchar(255),
	"state" char(2),
	"zipCode" integer,
	"county" varchar(255),
	"price" double precision,
	"favoritesForUser" varchar(30)[],
	"draft" boolean,
	"listingsCategory" "listingsCategory",
	"realEstateIncluded" boolean,
	"leasedLocation" boolean,
	"franchiseResale" boolean,
	"salesRevenue" double precision,
	"cashFlow" double precision,
	"supportAndTraining" text,
	"employees" integer,
	"established" integer,
	"internalListingNumber" integer,
	"reasonForSale" varchar(255),
	"brokerLicencing" varchar(255),
	"internals" text,
	"imageName" varchar(200),
	"created" timestamp,
	"updated" timestamp,
	"visits" integer,
	"lastVisit" timestamp,
	"latitude" double precision,
	"longitude" double precision
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "commercials" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"serial_id" serial NOT NULL,
	"email" varchar(255),
	"type" varchar(255),
	"title" varchar(255),
	"description" text,
	"city" varchar(255),
	"state" char(2),
	"price" double precision,
	"favoritesForUser" varchar(30)[],
	"listingsCategory" "listingsCategory",
	"hideImage" boolean,
	"draft" boolean,
	"zipCode" integer,
	"county" varchar(255),
	"imageOrder" varchar(200)[],
	"imagePath" varchar(200),
	"created" timestamp,
	"updated" timestamp,
	"visits" integer,
	"lastVisit" timestamp,
	"latitude" double precision,
	"longitude" double precision
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "users" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"firstname" varchar(255) NOT NULL,
	"lastname" varchar(255) NOT NULL,
	"email" varchar(255) NOT NULL,
	"phoneNumber" varchar(255),
	"description" text,
	"companyName" varchar(255),
	"companyOverview" text,
	"companyWebsite" varchar(255),
	"companyLocation" varchar(255),
	"offeredServices" text,
	"areasServed" jsonb,
	"hasProfile" boolean,
	"hasCompanyLogo" boolean,
	"licensedIn" jsonb,
	"gender" "gender",
	"customerType" "customerType",
	"customerSubType" "customerSubType",
	"created" timestamp,
	"updated" timestamp,
	"latitude" double precision,
	"longitude" double precision,
	CONSTRAINT "users_email_unique" UNIQUE("email")
);
--> statement-breakpoint
DO $$ BEGIN
 ALTER TABLE "businesses" ADD CONSTRAINT "businesses_email_users_email_fk" FOREIGN KEY ("email") REFERENCES "public"."users"("email") ON DELETE no action ON UPDATE no action;
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
 ALTER TABLE "commercials" ADD CONSTRAINT "commercials_email_users_email_fk" FOREIGN KEY ("email") REFERENCES "public"."users"("email") ON DELETE no action ON UPDATE no action;
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;
