-- Admin portal: workflow + audit columns.
-- Run after saas_schema.sql.

-- Coaching status workflow + admin notes
ALTER TABLE coaching_applications
    MODIFY COLUMN status VARCHAR(40) NOT NULL DEFAULT 'new',
    ADD COLUMN admin_notes TEXT AFTER consent_contact,
    ADD COLUMN replied_at  DATETIME DEFAULT NULL AFTER admin_notes;

-- Tier change audit (who set what tier, when, why)
CREATE TABLE IF NOT EXISTS user_tier_log (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    user_id INT UNSIGNED NOT NULL,
    old_tier VARCHAR(24),
    new_tier VARCHAR(24),
    changed_by_user_id INT UNSIGNED,
    reason VARCHAR(255),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    KEY idx_tlog_user (user_id),
    KEY idx_tlog_created (created_at)
);

-- Soft disable / suspend a user (without deleting)
ALTER TABLE users
    ADD COLUMN disabled TINYINT(1) NOT NULL DEFAULT 0,
    ADD COLUMN disabled_reason VARCHAR(255) DEFAULT NULL;
