-- Agregar columna para el Resumen IA estructurado
ALTER TABLE documentos ADD COLUMN IF NOT EXISTS resumen_ia JSONB DEFAULT NULL;

-- ============================================================
-- TABLA: tareas
-- ============================================================
CREATE TABLE IF NOT EXISTS tareas (
    id SERIAL PRIMARY KEY,
    documento_id INT NOT NULL REFERENCES documentos(id) ON DELETE CASCADE,
    descripcion_accion TEXT NOT NULL,
    fecha_limite DATE NOT NULL,
    estado VARCHAR(50) DEFAULT 'Pendiente',
    created_at TIMESTAMPTZ DEFAULT NOW(),
    updated_at TIMESTAMPTZ DEFAULT NOW()
);

-- Evitar error si el trigger ya existe
DROP TRIGGER IF EXISTS trg_tareas_updated_at ON tareas;

CREATE TRIGGER trg_tareas_updated_at
    BEFORE UPDATE ON tareas
    FOR EACH ROW EXECUTE FUNCTION update_updated_at();
