CREATE TABLE `admin_users` (
	`id` int AUTO_INCREMENT NOT NULL,
	`email` varchar(255) NOT NULL,
	`password_hash` text NOT NULL,
	`name` varchar(255) NOT NULL,
	`role` enum('admin','editor') NOT NULL DEFAULT 'editor',
	`is_active` boolean NOT NULL DEFAULT true,
	`last_login` timestamp,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `admin_users_id` PRIMARY KEY(`id`),
	CONSTRAINT `admin_users_email_unique` UNIQUE(`email`)
);
--> statement-breakpoint
CREATE TABLE `agents` (
	`id` int AUTO_INCREMENT NOT NULL,
	`name` varchar(255) NOT NULL,
	`email` varchar(255) NOT NULL,
	`phone` varchar(20) NOT NULL,
	`bio` text,
	`photo` varchar(500),
	`specialties` json DEFAULT ('[]'),
	`languages` json DEFAULT ('["English"]'),
	`years_experience` int,
	`is_active` boolean DEFAULT true,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `agents_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `enquiries` (
	`id` int AUTO_INCREMENT NOT NULL,
	`name` varchar(255) NOT NULL,
	`email` varchar(255) NOT NULL,
	`phone` varchar(20),
	`enquiry_type` enum('buy','sell','rent','invest','other') NOT NULL,
	`message` text,
	`property_id` int,
	`off_plan_id` int,
	`agent_id` int,
	`status` enum('new','contacted','closed') DEFAULT 'new',
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `enquiries_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `off_plan_projects` (
	`id` int AUTO_INCREMENT NOT NULL,
	`title` varchar(255) NOT NULL,
	`description` text,
	`location` varchar(255) NOT NULL,
	`city` varchar(100) NOT NULL,
	`developer` varchar(255) NOT NULL,
	`start_date` timestamp,
	`completion_date` timestamp,
	`completion_percentage` int DEFAULT 0,
	`total_units` int,
	`available_units` int,
	`price_from` decimal(15,2),
	`price_to` decimal(15,2),
	`payment_plan` text,
	`amenities` json DEFAULT ('[]'),
	`images` json DEFAULT ('[]'),
	`featured` boolean DEFAULT false,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `off_plan_projects_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `properties` (
	`id` int AUTO_INCREMENT NOT NULL,
	`title` varchar(255) NOT NULL,
	`description` text,
	`address` varchar(255) NOT NULL,
	`city` varchar(100) NOT NULL,
	`neighborhood` varchar(100),
	`type` enum('Villa','Apartment','Townhouse','Penthouse','Land','Commercial') NOT NULL,
	`status` enum('For Sale','For Rent','Sold','Rented') NOT NULL,
	`price` decimal(15,2) NOT NULL,
	`rent_price` decimal(12,2),
	`bedrooms` int,
	`bathrooms` int,
	`area_size` decimal(10,2),
	`year_built` int,
	`featured` boolean DEFAULT false,
	`images` json DEFAULT ('[]'),
	`amenities` json DEFAULT ('[]'),
	`agent_id` int,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `properties_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE INDEX `email_idx` ON `admin_users` (`email`);--> statement-breakpoint
CREATE INDEX `agent_email_idx` ON `agents` (`email`);--> statement-breakpoint
CREATE INDEX `enquiry_email_idx` ON `enquiries` (`email`);--> statement-breakpoint
CREATE INDEX `enquiry_status_idx` ON `enquiries` (`status`);--> statement-breakpoint
CREATE INDEX `offplan_city_idx` ON `off_plan_projects` (`city`);--> statement-breakpoint
CREATE INDEX `city_idx` ON `properties` (`city`);--> statement-breakpoint
CREATE INDEX `status_idx` ON `properties` (`status`);--> statement-breakpoint
CREATE INDEX `agent_idx` ON `properties` (`agent_id`);