CREATE TABLE IF NOT EXISTS `{{prefix}}doctor_chair_assignments` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `dentist_user_id` BIGINT UNSIGNED NOT NULL,
  `branch_id` BIGINT UNSIGNED NOT NULL,
  `chair_name` VARCHAR(100) NOT NULL,
  `is_active` TINYINT(1) NOT NULL DEFAULT 1,
  `created_by` BIGINT UNSIGNED NULL,
  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` DATETIME NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_doctor_chair_branch_doctor` (`dentist_user_id`,`branch_id`),
  UNIQUE KEY `uq_doctor_chair_branch_name` (`branch_id`,`chair_name`),
  KEY `idx_doctor_chair_active` (`branch_id`,`is_active`,`chair_name`),
  CONSTRAINT `{{prefix}}fk_doctor_chair_dentist` FOREIGN KEY (`dentist_user_id`) REFERENCES `{{prefix}}users` (`id`) ON DELETE CASCADE,
  CONSTRAINT `{{prefix}}fk_doctor_chair_branch` FOREIGN KEY (`branch_id`) REFERENCES `{{prefix}}branches` (`id`) ON DELETE CASCADE,
  CONSTRAINT `{{prefix}}fk_doctor_chair_creator` FOREIGN KEY (`created_by`) REFERENCES `{{prefix}}users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
