-- 014_clipboard_control.sql: Clipboard Control plugin (剪贴板管控)

CREATE TABLE IF NOT EXISTS clipboard_rules (
    id              INTEGER PRIMARY KEY AUTOINCREMENT,
    target_type     TEXT NOT NULL DEFAULT 'global' CHECK(target_type IN ('global', 'group', 'device')),
    target_id       TEXT,
    rule_type       TEXT NOT NULL DEFAULT 'block' CHECK(rule_type IN ('block', 'allow')),
    -- Direction: "out" = prevent clipboard data leaving the source app
    -- "in" = prevent pasting into the target app
    direction       TEXT NOT NULL DEFAULT 'out' CHECK(direction IN ('out', 'in', 'both')),
    source_process  TEXT,                    -- Process name pattern for source (copy from)
    target_process  TEXT,                    -- Process name pattern for target (paste to)
    content_pattern TEXT,                    -- Optional regex for content matching
    enabled         INTEGER NOT NULL DEFAULT 1,
    updated_at      TEXT NOT NULL DEFAULT (datetime('now'))
);

CREATE TABLE IF NOT EXISTS clipboard_violations (
    id              INTEGER PRIMARY KEY AUTOINCREMENT,
    device_uid      TEXT NOT NULL,
    source_process  TEXT,
    target_process  TEXT,
    content_preview TEXT,                    -- First N chars of clipboard content
    action_taken    TEXT NOT NULL DEFAULT 'blocked', -- "blocked", "allowed"
    timestamp       TEXT NOT NULL,
    reported_at     TEXT NOT NULL DEFAULT (datetime('now')),
    FOREIGN KEY (device_uid) REFERENCES devices(device_uid)
);

CREATE INDEX IF NOT EXISTS idx_clipboard_violations_device ON clipboard_violations(device_uid);
