-- DBN DMS migration 004 — tenant-managed categories
-- client_documents.category continues to store the slug as VARCHAR (back-compat).
-- This table just describes display metadata + lets tenants curate the list.

CREATE TABLE IF NOT EXISTS client_categories (
  id         INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  client_id  INT UNSIGNED NOT NULL,
  slug       VARCHAR(50)  NOT NULL,
  label      VARCHAR(100) NOT NULL,
  color      VARCHAR(7)   NULL,
  icon       VARCHAR(40)  NULL,
  sort_order SMALLINT     NOT NULL DEFAULT 0,
  is_system  TINYINT(1)   NOT NULL DEFAULT 0 COMMENT '1 = seeded default, cannot be deleted',
  created_at DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP,
  UNIQUE KEY uq_client_slug (client_id, slug),
  KEY idx_client (client_id),
  CONSTRAINT fk_cc_client FOREIGN KEY (client_id) REFERENCES clients(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
  COMMENT='Per-tenant category dictionary. Slug is the value used in client_documents.category.';
