"""first migration

Revision ID: 36b70d132a71
Revises: 
Create Date: 2024-06-12 13:43:20.918377

"""
from typing import Sequence, Union

import sqlalchemy as sa
import sqlmodel
from alembic import op

# revision identifiers, used by Alembic.
revision: str = '36b70d132a71'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None

sqlmodel_auto_string = sqlmodel.AutoString()


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('project',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('created_at', sa.DateTime(), nullable=True),
                    sa.Column('description', sqlmodel_auto_string, nullable=False),
                    sa.Column('status', sa.Enum('NOT_STARTED', 'IN_PROGRESS', 'COMPLETED', name='statustype'),
                              nullable=False),
                    sa.Column('name', sqlmodel_auto_string, nullable=False),
                    sa.Column('start_date', sa.DateTime(), nullable=True),
                    sa.Column('end_date', sa.DateTime(), nullable=True),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_table('user',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('created_at', sa.DateTime(), nullable=True),
                    sa.Column('name', sqlmodel_auto_string, nullable=False),
                    sa.Column('role', sa.Enum('ADMIN', 'TEST', name='userrole'), nullable=False),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_table('objective',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('created_at', sa.DateTime(), nullable=True),
                    sa.Column('description', sqlmodel_auto_string, nullable=False),
                    sa.Column('status', sa.Enum('NOT_STARTED', 'IN_PROGRESS', 'COMPLETED', name='statustype'),
                              nullable=False),
                    sa.Column('name', sqlmodel_auto_string, nullable=False),
                    sa.Column('start_date', sa.DateTime(), nullable=True),
                    sa.Column('end_date', sa.DateTime(), nullable=True),
                    sa.Column('project_id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(['project_id'], ['project.id'], ),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_table('keyresult',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('created_at', sa.DateTime(), nullable=True),
                    sa.Column('description', sqlmodel_auto_string, nullable=False),
                    sa.Column('status', sa.Enum('NOT_STARTED', 'IN_PROGRESS', 'COMPLETED', name='statustype'),
                              nullable=False),
                    sa.Column('name', sqlmodel_auto_string, nullable=False),
                    sa.Column('start_date', sa.DateTime(), nullable=True),
                    sa.Column('end_date', sa.DateTime(), nullable=True),
                    sa.Column('objective_id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(['objective_id'], ['objective.id'], ),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_table('requirement',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('created_at', sa.DateTime(), nullable=True),
                    sa.Column('description', sqlmodel_auto_string, nullable=False),
                    sa.Column('status', sa.Enum('NOT_STARTED', 'IN_PROGRESS', 'COMPLETED', name='statustype'),
                              nullable=False),
                    sa.Column('name', sqlmodel_auto_string, nullable=False),
                    sa.Column('start_date', sa.DateTime(), nullable=True),
                    sa.Column('end_date', sa.DateTime(), nullable=True),
                    sa.Column('key_result_id', sa.Integer(), nullable=False),
                    sa.Column('necessity', sa.Enum('MUST', 'SHOULD', 'COULD', 'WONT', name='necessitytype'),
                              nullable=False),
                    sa.ForeignKeyConstraint(['key_result_id'], ['keyresult.id'], ),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_table('scopedtask',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('created_at', sa.DateTime(), nullable=True),
                    sa.Column('description', sqlmodel_auto_string, nullable=False),
                    sa.Column('status', sa.Enum('NOT_STARTED', 'IN_PROGRESS', 'COMPLETED', name='statustype'),
                              nullable=False),
                    sa.Column('name', sqlmodel_auto_string, nullable=False),
                    sa.Column('start_date', sa.DateTime(), nullable=True),
                    sa.Column('end_date', sa.DateTime(), nullable=True),
                    sa.Column('requirement_id', sa.Integer(), nullable=False),
                    sa.Column('assignee', sa.Enum('CODER', 'CTO', 'CEO', 'COO', name='assigneetype'), nullable=True),
                    sa.Column('priority', sa.Enum('HIGH', 'MEDIUM', 'LOW', name='prioritytype'), nullable=True),
                    sa.Column('task_type',
                              sa.Enum('FRONTEND', 'SVC_IMPL', 'UNIT_TEST', 'INTERFACE', 'DATA_MODEL', 'SCOPED_TASK',
                                      'REQUIREMENT', 'ARCHITECTURE', 'INFRASTRUCTURE', 'PROTOTYPE', 'ROADMAP', 'OKR',
                                      'COMPLIANCE', 'DOCUMENTATION', 'UNDEFINED', name='tasktype'), nullable=True),
                    sa.ForeignKeyConstraint(['requirement_id'], ['requirement.id'], ),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_table('scopedtaskstep',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('created_at', sa.DateTime(), nullable=True),
                    sa.Column('task_id', sa.Integer(), nullable=False),
                    sa.Column('action', sqlmodel_auto_string, nullable=False),
                    sa.Column('status', sa.Enum('NOT_STARTED', 'IN_PROGRESS', 'COMPLETED', name='statustype'),
                              nullable=False),
                    sa.Column('expected_result', sqlmodel_auto_string, nullable=True),
                    sa.ForeignKeyConstraint(['task_id'], ['scopedtask.id'], ),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_table('userprompt',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('created_at', sa.DateTime(), nullable=True),
                    sa.Column('prompt_text', sqlmodel_auto_string, nullable=False),
                    sa.Column('response_class_name', sqlmodel_auto_string, nullable=True),
                    sa.Column('input_files', sa.JSON(), nullable=False),
                    sa.Column('output_files', sa.JSON(), nullable=False),
                    sa.Column('llm_model_name',
                              sa.Enum('GPT_3', 'GPT_4', 'CLAUDE_3_0', 'CLAUDE_3_1', 'CLAUDE_3_2', name='modelnamellm'),
                              nullable=False),
                    sa.Column('scoped_task_id', sa.Integer(), nullable=True),
                    sa.ForeignKeyConstraint(['scoped_task_id'], ['scopedtask.id'], ),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_table('aitask',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('created_at', sa.DateTime(), nullable=True),
                    sa.Column('llm_model_name',
                              sa.Enum('GPT_3', 'GPT_4', 'CLAUDE_3_0', 'CLAUDE_3_1', 'CLAUDE_3_2', name='modelnamellm'),
                              nullable=False),
                    sa.Column('prompt_text', sqlmodel_auto_string, nullable=False),
                    sa.Column('status', sa.Enum('PENDING', 'IN_PROGRESS', 'COMPLETED', 'FAILED', name='aitaskstatus'),
                              nullable=False),
                    sa.Column('user_prompt_id', sa.Integer(), nullable=False),
                    sa.Column('scoped_task_id', sa.Integer(), nullable=True),
                    sa.ForeignKeyConstraint(['scoped_task_id'], ['scopedtask.id'], ),
                    sa.ForeignKeyConstraint(['user_prompt_id'], ['userprompt.id'], ),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_table('taskcontext',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('created_at', sa.DateTime(), nullable=True),
                    sa.Column('response_format', sa.JSON(), nullable=True),
                    sa.Column('project_context', sa.JSON(), nullable=True),
                    sa.Column('input_files', sa.JSON(), nullable=False),
                    sa.Column('output_files', sa.JSON(), nullable=False),
                    sa.Column('ai_task_id', sa.Integer(), nullable=True),
                    sa.Column('scoped_task_id', sa.Integer(), nullable=True),
                    sa.ForeignKeyConstraint(['ai_task_id'], ['aitask.id'], ),
                    sa.ForeignKeyConstraint(['scoped_task_id'], ['scopedtask.id'], ),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_table('taskmessage',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('created_at', sa.DateTime(), nullable=True),
                    sa.Column('content', sqlmodel_auto_string, nullable=False),
                    sa.Column('role', sa.Enum('USER', 'ASSISTANT', name='messagerole'), nullable=False),
                    sa.Column('ai_task_id', sa.Integer(), nullable=True),
                    sa.ForeignKeyConstraint(['ai_task_id'], ['aitask.id'], ),
                    sa.PrimaryKeyConstraint('id')
                    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('taskmessage')
    op.drop_table('taskcontext')
    op.drop_table('aitask')
    op.drop_table('userprompt')
    op.drop_table('scopedtaskstep')
    op.drop_table('scopedtask')
    op.drop_table('requirement')
    op.drop_table('keyresult')
    op.drop_table('objective')
    op.drop_table('user')
    op.drop_table('project')
    # ### end Alembic commands ###
