-- KeyHunter database schema
-- Version: 1

CREATE TABLE IF NOT EXISTS scans (
    id            INTEGER PRIMARY KEY AUTOINCREMENT,
    started_at    DATETIME NOT NULL,
    finished_at   DATETIME,
    source_path   TEXT,
    finding_count INTEGER DEFAULT 0,
    created_at    DATETIME DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS findings (
    id                   INTEGER PRIMARY KEY AUTOINCREMENT,
    scan_id              INTEGER REFERENCES scans(id),
    provider_name        TEXT NOT NULL,
    key_value            BLOB NOT NULL,
    key_masked           TEXT NOT NULL,
    confidence           TEXT NOT NULL,
    source_path          TEXT,
    source_type          TEXT,
    line_number          INTEGER,
    verified             INTEGER NOT NULL DEFAULT 0,
    verify_status        TEXT NOT NULL DEFAULT '',
    verify_http_code     INTEGER NOT NULL DEFAULT 0,
    verify_metadata_json TEXT,
    created_at           DATETIME DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS settings (
    key        TEXT PRIMARY KEY,
    value      TEXT NOT NULL,
    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

-- Indexes for common queries
CREATE INDEX IF NOT EXISTS idx_findings_scan_id ON findings(scan_id);
CREATE INDEX IF NOT EXISTS idx_findings_provider ON findings(provider_name);
CREATE INDEX IF NOT EXISTS idx_findings_created ON findings(created_at DESC);
