-- +goose Up
CREATE TABLE product_recognition_jobs (
    id           UUID        PRIMARY KEY DEFAULT uuid_generate_v7(),
    user_id      UUID        NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    user_plan    TEXT        NOT NULL,
    job_type     TEXT        NOT NULL CHECK (job_type IN ('receipt', 'products')),
    images       JSONB       NOT NULL,
    lang         TEXT        NOT NULL DEFAULT 'en',
    status       TEXT        NOT NULL DEFAULT 'pending',
    result       JSONB,
    error        TEXT,
    created_at   TIMESTAMPTZ NOT NULL DEFAULT now(),
    started_at   TIMESTAMPTZ,
    completed_at TIMESTAMPTZ
);

CREATE INDEX idx_product_recognition_jobs_user
    ON product_recognition_jobs (user_id, created_at DESC);

CREATE INDEX idx_product_recognition_jobs_status
    ON product_recognition_jobs (status, user_plan, created_at ASC);

-- +goose Down
DROP TABLE IF EXISTS product_recognition_jobs;
