CREATE TABLE IF NOT EXISTS community.push_notification_device (
    id BIGSERIAL PRIMARY KEY,
    user_id INTEGER NOT NULL REFERENCES community."user"(id) ON DELETE CASCADE,
    token TEXT NOT NULL UNIQUE,
    platform VARCHAR(20) NOT NULL DEFAULT 'android',
    enabled BOOLEAN NOT NULL DEFAULT TRUE,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    CONSTRAINT push_notification_device_platform_check CHECK (platform IN ('android'))
);

CREATE INDEX IF NOT EXISTS push_notification_device_user_enabled_idx
    ON community.push_notification_device (user_id, enabled);

CREATE TABLE IF NOT EXISTS community.push_notification_setting (
    user_id INTEGER PRIMARY KEY REFERENCES community."user"(id) ON DELETE CASCADE,
    enabled BOOLEAN NOT NULL DEFAULT FALSE,
    chat_enabled BOOLEAN NOT NULL DEFAULT TRUE,
    friend_login_enabled BOOLEAN NOT NULL DEFAULT TRUE,
    falukant_enabled BOOLEAN NOT NULL DEFAULT TRUE,
    vocab_reminder_enabled BOOLEAN NOT NULL DEFAULT TRUE,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
