-- ============================================================
--  Break the Locks — Part 11 (Reprogram Yourself) Schema
--  Run once in phpMyAdmin on the admin_btlc database.
--
--  Tables:
--    user_miracles            — moments the user notices that show
--                               their alignment is working
--    user_potential_callings  — things they notice that might be a
--                               calling, to consider later
--    user_truth_declarations  — needs converted into present-tense
--                               truths + visualization scenes
--    user_reprogram_log       — one row per day they completed the
--                               daily recitation (drives streak)
--    user_telling_log         — the "tell-others" hack: who they
--                               told what + how the person responded
-- ============================================================

CREATE TABLE IF NOT EXISTS `user_miracles` (
  `id`         INT AUTO_INCREMENT PRIMARY KEY,
  `user_id`    INT NOT NULL,
  `text`       VARCHAR(2000) NOT NULL,
  `noticed_at` DATE NOT NULL,
  `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  INDEX `idx_user` (`user_id`),
  INDEX `idx_user_date` (`user_id`, `noticed_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `user_potential_callings` (
  `id`         INT AUTO_INCREMENT PRIMARY KEY,
  `user_id`    INT NOT NULL,
  `text`       VARCHAR(2000) NOT NULL,
  `noticed_at` DATE NOT NULL,
  `promoted`   TINYINT(1) NOT NULL DEFAULT 0,
  `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  INDEX `idx_user` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `user_truth_declarations` (
  `id`                 INT AUTO_INCREMENT PRIMARY KEY,
  `user_id`            INT NOT NULL,
  `source_need_text`   VARCHAR(800) NULL,
  `truth_text`         VARCHAR(2000) NOT NULL,
    -- Present-tense "I am" / "I have" — claimed as already real
  `visualization_text` TEXT NULL,
    -- AI-generated vivid scene the user closes their eyes and sees
  `created_at`         TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  INDEX `idx_user` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `user_reprogram_log` (
  `id`         INT AUTO_INCREMENT PRIMARY KEY,
  `user_id`    INT NOT NULL,
  `log_date`   DATE NOT NULL,
  `recited_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  UNIQUE KEY `uq_user_date` (`user_id`, `log_date`),
  INDEX `idx_user` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `user_telling_log` (
  `id`            INT AUTO_INCREMENT PRIMARY KEY,
  `user_id`       INT NOT NULL,
  `person_name`   VARCHAR(200) NOT NULL,
  `what_told`     VARCHAR(2000) NOT NULL,
  `response_type` ENUM('supportive','neutral','negative') NULL,
    -- Capture how the person responded, so the user can see which
    -- relationships accelerate vs. slow their reprogramming
  `told_on`       DATE NOT NULL,
  `notes`         TEXT NULL,
  `created_at`    TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  INDEX `idx_user` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
