-- ============================================================
--  Break the Locks — Part 9 (Architect New Identity) Schema
--  Run once in phpMyAdmin on the admin_btlc database.
--
--  TABLE 1: user_identity_blockers
--    The things that would STOP the user from achieving an
--    aspiration. AI-suggested "opposite" traits are cached
--    here as JSON so we don't re-query OpenAI.
--
--  TABLE 2: user_identity_traits
--    The traits the user has adopted into their new identity.
--    Either picked from an AI suggestion (blocker_id set) or
--    typed directly (is_custom=1).
-- ============================================================

CREATE TABLE IF NOT EXISTS `user_identity_blockers` (
  `id`               INT AUTO_INCREMENT PRIMARY KEY,
  `user_id`          INT NOT NULL,
  `aspiration_type`  VARCHAR(32) NOT NULL,
    -- purpose | calling | need | goal | custom
  `aspiration_ref`   VARCHAR(64) NULL,
  `aspiration_text`  VARCHAR(500) NOT NULL,
  `text`             VARCHAR(500) NOT NULL,
  `suggestions`      TEXT NULL,
    -- JSON array of AI-suggested opposite traits
  `created_at`       TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  INDEX `idx_user` (`user_id`),
  INDEX `idx_user_aspiration` (`user_id`, `aspiration_type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `user_identity_traits` (
  `id`              INT AUTO_INCREMENT PRIMARY KEY,
  `user_id`         INT NOT NULL,
  `blocker_id`      INT NULL,
  `aspiration_type` VARCHAR(32) NULL,
  `aspiration_ref`  VARCHAR(64) NULL,
  `text`            VARCHAR(500) NOT NULL,
  `is_custom`       TINYINT(1) NOT NULL DEFAULT 0,
  `created_at`      TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  INDEX `idx_user` (`user_id`),
  INDEX `idx_blocker` (`blocker_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
