-- Baltique OS Core 0.9.4 — Layout Architect
-- Adds layout snapshots for editable clinic/OR floorplans. Main live layout remains stored on clinic_resources layout_x/layout_y/layout_w/layout_h.
SET NAMES utf8mb4;

CREATE TABLE IF NOT EXISTS clinic_layout_snapshots (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  location_id BIGINT UNSIGNED NULL,
  snapshot_name VARCHAR(190) NOT NULL,
  snapshot_status ENUM('draft','live','archived') NOT NULL DEFAULT 'draft',
  canvas_width INT UNSIGNED NOT NULL DEFAULT 1600,
  canvas_height INT UNSIGNED NOT NULL DEFAULT 980,
  snapshot_json LONGTEXT NULL,
  notes TEXT NULL,
  created_by_user_id BIGINT UNSIGNED NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  published_at DATETIME NULL,
  PRIMARY KEY (id),
  KEY idx_cls_location_status (location_id, snapshot_status, created_at),
  CONSTRAINT fk_cls_location FOREIGN KEY (location_id) REFERENCES locations(id) ON DELETE SET NULL,
  CONSTRAINT fk_cls_user FOREIGN KEY (created_by_user_id) REFERENCES users(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO app_settings (setting_key, setting_value, created_at, updated_at) VALUES
('core_version','0.9.4',NOW(),NOW()),
('layout_architect_enabled','1',NOW(),NOW()),
('layout_architect_canvas_width','1600',NOW(),NOW()),
('layout_architect_canvas_height','980',NOW(),NOW()),
('layout_architect_grid_size','10',NOW(),NOW())
ON DUPLICATE KEY UPDATE setting_value=VALUES(setting_value), updated_at=NOW();
