-- Wall Dashboard — MariaDB schema (reference only).
-- The application creates these tables automatically on first run via inc.php,
-- so you do NOT need to run this by hand. It is here for documentation and if
-- you prefer to create the tables yourself in phpMyAdmin.

CREATE TABLE IF NOT EXISTS wd_settings (
  k VARCHAR(64) PRIMARY KEY,
  v TEXT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- keys used: admin_hash (bcrypt), enrol_token

CREATE TABLE IF NOT EXISTS wd_pages (
  id CHAR(12) PRIMARY KEY,
  name VARCHAR(120) NOT NULL,
  config MEDIUMTEXT NOT NULL,       -- JSON dashboard config
  updated_at BIGINT NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS wd_displays (
  id CHAR(12) PRIMARY KEY,
  name VARCHAR(120) NOT NULL,
  dkey CHAR(64) NOT NULL,            -- SHA-256 of the device's secret key
  status VARCHAR(10) NOT NULL DEFAULT 'active',  -- 'pending' | 'active'
  pair_code VARCHAR(12) NULL,        -- short code shown on screen while pending
  hwid VARCHAR(128) NULL,            -- optional hardware id reported by the device
  assign_type VARCHAR(10) NOT NULL DEFAULT 'page',   -- 'page' | 'playlist'
  page_id CHAR(12) NULL,
  playlist MEDIUMTEXT NULL,          -- JSON [{pageId,secs}]
  sleep_start TINYINT NULL,
  sleep_end TINYINT NULL,
  command VARCHAR(20) NULL,          -- reload | identify | blank | wake
  command_ts BIGINT NULL,           -- ms timestamp of last command
  last_seen BIGINT NULL,
  ua VARCHAR(255) NULL,
  created_at BIGINT NOT NULL,
  UNIQUE KEY uniq_dkey (dkey)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS wd_throttle (
  ip VARCHAR(64) PRIMARY KEY,
  cnt INT NOT NULL,
  ts BIGINT NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
