-- =============================================================================
-- Migration: Add sharing_settings table for Mutual Sharing & Transparency Layer
-- =============================================================================

CREATE TABLE IF NOT EXISTS sharing_settings (
    couple_id  BIGINT UNSIGNED NOT NULL,
    user_id    BIGINT UNSIGNED NOT NULL,
    item       VARCHAR(32)     NOT NULL, -- 'mood', 'live_location', 'battery_level', 'status'
    enabled    TINYINT(1)      NOT NULL DEFAULT 0,
    updated_at DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

    PRIMARY KEY (couple_id, user_id, item),
    CONSTRAINT fk_sharing_couple FOREIGN KEY (couple_id) REFERENCES couples(id) ON DELETE CASCADE,
    CONSTRAINT fk_sharing_user   FOREIGN KEY (user_id)   REFERENCES users(id)   ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
