-- +goose Up
-- +goose StatementBegin

-- Add new prompt types for agent supervision
CREATE TYPE PROMPT_TYPE_NEW AS ENUM (
  'primary_agent',
  'assistant',
  'pentester',
  'question_pentester',
  'coder',
  'question_coder',
  'installer',
  'question_installer',
  'searcher',
  'question_searcher',
  'memorist',
  'question_memorist',
  'adviser',
  'question_adviser',
  'generator',
  'subtasks_generator',
  'refiner',
  'subtasks_refiner',
  'reporter',
  'task_reporter',
  'reflector',
  'question_reflector',
  'enricher',
  'question_enricher',
  'toolcall_fixer',
  'input_toolcall_fixer',
  'summarizer',
  'image_chooser',
  'language_chooser',
  'flow_descriptor',
  'task_descriptor',
  'execution_logs',
  'full_execution_context',
  'short_execution_context',
  'tool_call_id_collector',
  'tool_call_id_detector',
  'question_execution_monitor',
  'question_task_planner',
  'task_assignment_wrapper'
);

-- Update the searchlogs table to use the new enum type
ALTER TABLE prompts
    ALTER COLUMN type TYPE PROMPT_TYPE_NEW USING type::text::PROMPT_TYPE_NEW;

-- Drop the old type and rename the new one
DROP TYPE PROMPT_TYPE;
ALTER TYPE PROMPT_TYPE_NEW RENAME TO PROMPT_TYPE;

-- Set the column as NOT NULL
ALTER TABLE prompts
    ALTER COLUMN type SET NOT NULL;
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin

-- Revert the changes by removing agent supervision prompt types from the enum
CREATE TYPE PROMPT_TYPE_NEW AS ENUM (
  'primary_agent',
  'assistant',
  'pentester',
  'question_pentester',
  'coder',
  'question_coder',
  'installer',
  'question_installer',
  'searcher',
  'question_searcher',
  'memorist',
  'question_memorist',
  'adviser',
  'question_adviser',
  'generator',
  'subtasks_generator',
  'refiner',
  'subtasks_refiner',
  'reporter',
  'task_reporter',
  'reflector',
  'question_reflector',
  'enricher',
  'question_enricher',
  'toolcall_fixer',
  'input_toolcall_fixer',
  'summarizer',
  'image_chooser',
  'language_chooser',
  'flow_descriptor',
  'task_descriptor',
  'execution_logs',
  'full_execution_context',
  'short_execution_context',
  'tool_call_id_collector',
  'tool_call_id_detector'
);

-- Update the prompts table to use the new enum type
ALTER TABLE prompts
    ALTER COLUMN type TYPE PROMPT_TYPE_NEW USING type::text::PROMPT_TYPE_NEW;

-- Drop the old type and rename the new one
DROP TYPE PROMPT_TYPE;
ALTER TYPE PROMPT_TYPE_NEW RENAME TO PROMPT_TYPE;

-- Set the column as NOT NULL
ALTER TABLE prompts
    ALTER COLUMN type SET NOT NULL;
-- +goose StatementEnd
