CREATE TABLE IF NOT EXISTS folders
(
    id                  UUID PRIMARY KEY         DEFAULT gen_random_uuid(),
    path                TEXT NOT NULL UNIQUE,
    parent_path         TEXT,
    disk_label          VARCHAR(50),

    file_count          INT                      DEFAULT 0,
    total_size          BIGINT                   DEFAULT 0,

    project_type        VARCHAR(50),
    intent              TEXT,
    summary             TEXT,

    has_readme          BOOLEAN                  DEFAULT FALSE,
    has_git             BOOLEAN                  DEFAULT FALSE,
    has_manifest        BOOLEAN                  DEFAULT FALSE,
    manifest_types      TEXT[],
    dominant_file_types JSONB,

    structure           JSONB,

    created_at          TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    updated_at          TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX IF NOT EXISTS idx_folders_path ON folders (path);
CREATE INDEX IF NOT EXISTS idx_folders_parent ON folders (parent_path);
CREATE INDEX IF NOT EXISTS idx_folders_disk ON folders (disk_label);
CREATE INDEX IF NOT EXISTS idx_folders_project_type ON folders (project_type);

CREATE TABLE IF NOT EXISTS processing_checkpoints
(
    task_name           VARCHAR(100) PRIMARY KEY,
    last_processed_id   TEXT,
    last_processed_path TEXT,
    processed_count     INT                      DEFAULT 0,
    total_count         INT,
    started_at          TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    updated_at          TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
