CREATE TABLE `users` (
	`id` varchar(36) NOT NULL,
	`username` varchar(50) NOT NULL,
	`password_hash` varchar(255),
	`email` varchar(100) NOT NULL,
	`role` varchar(20) NOT NULL DEFAULT 'MANAGER',
	`is_maid_also` boolean NOT NULL DEFAULT false,
	`is_active` boolean NOT NULL DEFAULT true,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`archived_at` timestamp,
	CONSTRAINT `users_id` PRIMARY KEY(`id`),
	CONSTRAINT `users_username_unique` UNIQUE(`username`),
	CONSTRAINT `users_email_unique` UNIQUE(`email`)
);
--> statement-breakpoint
CREATE TABLE `employees` (
	`id` varchar(4) NOT NULL,
	`full_name` varchar(255) NOT NULL,
	`position` varchar(100) NOT NULL,
	`birth_date` date,
	`address` text,
	`phone` varchar(20) NOT NULL,
	`email` varchar(100) NOT NULL,
	`notes` text,
	`is_fired` boolean NOT NULL DEFAULT false,
	`fired_reason` text,
	`user_id` varchar(36),
	`created_at` varchar(36) NOT NULL,
	`updated_at` varchar(36) NOT NULL,
	`archived_at` varchar(36),
	CONSTRAINT `employees_id` PRIMARY KEY(`id`),
	CONSTRAINT `employees_email_unique` UNIQUE(`email`)
);
--> statement-breakpoint
CREATE TABLE `notes` (
	`id` varchar(36) NOT NULL,
	`title` varchar(255) NOT NULL,
	`content` text NOT NULL,
	`author_id` varchar(36) NOT NULL,
	`priority` enum('low','normal','high') NOT NULL DEFAULT 'normal',
	`status` enum('active','deferred','done','cancelled') NOT NULL DEFAULT 'active',
	`column` int NOT NULL DEFAULT 1,
	`position_y` int NOT NULL DEFAULT 0,
	`height` int NOT NULL DEFAULT 220,
	`is_public` boolean NOT NULL DEFAULT false,
	`reminder_at` timestamp,
	`defer_until` timestamp,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`archived_at` timestamp,
	CONSTRAINT `notes_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `note_comments` (
	`id` varchar(36) NOT NULL,
	`note_id` varchar(36) NOT NULL,
	`author_id` varchar(36) NOT NULL,
	`content` text NOT NULL,
	`is_read` boolean NOT NULL DEFAULT false,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `note_comments_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `note_history` (
	`id` varchar(36) NOT NULL,
	`note_id` varchar(36) NOT NULL,
	`action` enum('created','updated','status_changed','commented','returned') NOT NULL,
	`payload` json,
	`author_id` varchar(36) NOT NULL,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `note_history_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `shifts` (
	`id` varchar(36) NOT NULL,
	`date` date NOT NULL,
	`user_id` varchar(36) NOT NULL,
	`role_at_shift` varchar(20) NOT NULL,
	`status` varchar(20) NOT NULL DEFAULT 'Blank',
	`is_approved` boolean NOT NULL DEFAULT false,
	`created_by` varchar(36) NOT NULL,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`archived_at` timestamp,
	CONSTRAINT `shifts_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `shift_tasks` (
	`id` varchar(36) NOT NULL,
	`text` text NOT NULL,
	`is_completed` boolean NOT NULL DEFAULT false,
	`parent_id` varchar(36),
	`date` date NOT NULL,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`archived_at` timestamp,
	CONSTRAINT `shift_tasks_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `tasks` (
	`id` varchar(36) NOT NULL,
	`text` text NOT NULL,
	`is_completed` boolean NOT NULL DEFAULT false,
	`parent_id` varchar(36),
	`date` date NOT NULL,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`archived_at` timestamp,
	CONSTRAINT `tasks_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `checkins` (
	`id` varchar(36) NOT NULL,
	`guest_name` varchar(255) NOT NULL,
	`room_number` varchar(10) NOT NULL,
	`check_in_time` timestamp NOT NULL,
	`check_out_time` timestamp,
	`date` timestamp NOT NULL,
	`is_archived` boolean NOT NULL DEFAULT false,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `checkins_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `linen` (
	`id` varchar(36) NOT NULL,
	`room_number` varchar(10) NOT NULL,
	`type` varchar(50) NOT NULL,
	`quantity` int NOT NULL,
	`status` varchar(50) NOT NULL,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `linen_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `daily_checkins` (
	`id` varchar(36) NOT NULL,
	`date` timestamp NOT NULL,
	`room_number` varchar(10) NOT NULL,
	`guest_name` varchar(255) NOT NULL,
	`guest_count` int NOT NULL DEFAULT 1,
	`check_in_time` timestamp,
	`check_out_time` timestamp,
	`check_out_info` varchar(500),
	`cleaning_status` varchar(50) NOT NULL DEFAULT 'DIRTY',
	`linen_dispatched` boolean NOT NULL DEFAULT false,
	`linen_data` json,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`archived_at` timestamp,
	CONSTRAINT `daily_checkins_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `inv_linen` (
	`id` varchar(36) NOT NULL,
	`name` varchar(255) NOT NULL,
	`type` varchar(50) NOT NULL,
	`weight` decimal(5,2) NOT NULL,
	`unit` varchar(20) NOT NULL DEFAULT 'шт',
	`description` varchar(500),
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`archived_at` timestamp,
	CONSTRAINT `inv_linen_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `linen_dispatch_log` (
	`id` varchar(36) NOT NULL,
	`date` timestamp NOT NULL,
	`total_weight` varchar(50) NOT NULL,
	`items` json NOT NULL,
	`dispatched_by` varchar(36),
	`created_at` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `linen_dispatch_log_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `paymaster_rows` (
	`id` varchar(36) NOT NULL,
	`description` varchar(500) NOT NULL,
	`type` varchar(50) NOT NULL,
	`amount` decimal(10,2) NOT NULL,
	`comment` varchar(500),
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`archived_at` timestamp,
	CONSTRAINT `paymaster_rows_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `approval_requests` (
	`id` varchar(36) NOT NULL,
	`entity_type` varchar(50) NOT NULL,
	`target_id` varchar(36),
	`requester_id` varchar(36) NOT NULL,
	`payload` json NOT NULL,
	`status` varchar(20) NOT NULL DEFAULT 'pending',
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`archived_at` timestamp,
	CONSTRAINT `approval_requests_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `blacklist` (
	`id` varchar(36) NOT NULL,
	`name` varchar(100) NOT NULL,
	`phone` varchar(20) NOT NULL,
	`booking_engine_check` varchar(20) NOT NULL DEFAULT 'NO',
	`comment` text,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`archived_at` timestamp,
	CONSTRAINT `blacklist_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `external_access` (
	`id` varchar(36) NOT NULL,
	`resource_name` varchar(100) NOT NULL,
	`link` varchar(500) NOT NULL,
	`login` varchar(100) NOT NULL,
	`password` varchar(100) NOT NULL,
	`comment` text,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`archived_at` timestamp,
	CONSTRAINT `external_access_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `contractors` (
	`id` varchar(36) NOT NULL,
	`name` varchar(100) NOT NULL,
	`category` varchar(50) NOT NULL,
	`contract_number` varchar(100),
	`phone` varchar(20) NOT NULL,
	`email` varchar(100),
	`web_link` varchar(500),
	`manager_name` varchar(100),
	`manager_phone` varchar(20),
	`manager_email` varchar(100),
	`comment` text,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`archived_at` timestamp,
	CONSTRAINT `contractors_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `local_it` (
	`id` varchar(36) NOT NULL,
	`description` varchar(255) NOT NULL,
	`manufacturer` varchar(100),
	`model` varchar(100),
	`network_address` varchar(50),
	`access_ports` json,
	`username` varchar(100),
	`password` varchar(100),
	`location` varchar(100) NOT NULL,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`archived_at` timestamp,
	CONSTRAINT `local_it_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `local_security` (
	`id` varchar(36) NOT NULL,
	`type` varchar(50) NOT NULL,
	`manufacturer` varchar(100),
	`model` varchar(100),
	`location` varchar(100) NOT NULL,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`archived_at` timestamp,
	CONSTRAINT `local_security_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `other_equipment` (
	`id` varchar(36) NOT NULL,
	`description` varchar(255) NOT NULL,
	`type` varchar(50),
	`manufacturer` varchar(100),
	`model` varchar(100),
	`location` varchar(100) NOT NULL,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`archived_at` timestamp,
	CONSTRAINT `other_equipment_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `inventory` (
	`id` varchar(36) NOT NULL,
	`name` varchar(100) NOT NULL,
	`category` varchar(50) NOT NULL,
	`quantity` decimal(10,2) NOT NULL,
	`unit` varchar(20),
	`location` varchar(100) NOT NULL,
	`comment` text,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`archived_at` timestamp,
	CONSTRAINT `inventory_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `inventory_details` (
	`id` varchar(36) NOT NULL,
	`inventory_id` varchar(36) NOT NULL,
	`manufacturer` varchar(100),
	`model` varchar(100),
	`ordering_link` varchar(500),
	`article_number` varchar(100),
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`archived_at` timestamp,
	CONSTRAINT `inventory_details_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `pending_notifications` (
	`id` varchar(36) NOT NULL,
	`user_id` varchar(36) NOT NULL,
	`room_id` varchar(50) NOT NULL,
	`event` varchar(50) NOT NULL,
	`data` json NOT NULL,
	`read_at` timestamp,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`archived_at` timestamp,
	CONSTRAINT `pending_notifications_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
ALTER TABLE `note_comments` ADD CONSTRAINT `note_comments_note_id_notes_id_fk` FOREIGN KEY (`note_id`) REFERENCES `notes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `note_comments` ADD CONSTRAINT `note_comments_author_id_users_id_fk` FOREIGN KEY (`author_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `note_history` ADD CONSTRAINT `note_history_note_id_notes_id_fk` FOREIGN KEY (`note_id`) REFERENCES `notes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `note_history` ADD CONSTRAINT `note_history_author_id_users_id_fk` FOREIGN KEY (`author_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;