-- +goose Up
-- Create chat_interactions table
CREATE TABLE IF NOT EXISTS chat_interactions (
    id BIGSERIAL PRIMARY KEY,
    created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    correlation_id TEXT NOT NULL,
    user_message TEXT NOT NULL,
    translate TEXT,
    animal TEXT,
    keywords TEXT[] NOT NULL,
    best_visit_id TEXT,
    total_price INT,
    total_duration INT
);

-- Create chat_llm_raw table
CREATE TABLE IF NOT EXISTS chat_llm_raw (
    id BIGSERIAL PRIMARY KEY,
    created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    correlation_id TEXT NOT NULL,
    phase TEXT NOT NULL,
    raw_json TEXT
);

-- Create knowledgeModel table
CREATE TABLE IF NOT EXISTS knowledgeModel (
    id BIGSERIAL PRIMARY KEY,
    created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    knowledge_text TEXT NOT NULL
);

-- Drop legacy columns if they exist
ALTER TABLE chat_interactions DROP COLUMN IF EXISTS raw_keywords_json;
ALTER TABLE chat_interactions DROP COLUMN IF EXISTS raw_disambig_json;

-- +goose Down
DROP TABLE IF EXISTS chat_llm_raw;
DROP TABLE IF EXISTS chat_interactions;
DROP TABLE IF EXISTS knowledgeModel;
