"""Add default role and statuses

Revision ID: e68f981950f8
Revises: 018c20e341ef
Create Date: 2025-03-16 17:26:22.805685

"""
import uuid
from typing import Sequence, Union

from alembic import op

from src.common.utils.default_enums import UserRoleDefault, TicketStatusDefault, TicketTypeDefault

# revision identifiers, used by Alembic.
revision: str = '1ee22bd8371d'
down_revision: Union[str, None] = '583b481614b0'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.execute(f"""
            INSERT INTO user_roles (id, name)
            VALUES
            ('{uuid.uuid4()}', '{UserRoleDefault.USER.value}')
            ON CONFLICT (name) DO NOTHING;
        """)

    op.execute(f"""
            INSERT INTO ticket_statuses (id, name)
            VALUES
            ('{uuid.uuid4()}', '{TicketStatusDefault.CREATED.value}'),
                   ('{uuid.uuid4()}', '{TicketStatusDefault.IN_PROGRESS.value}'),
                   ('{uuid.uuid4()}', '{TicketStatusDefault.COMPLETED.value}'),
                   ('{uuid.uuid4()}', '{TicketStatusDefault.FAILED.value}')
            ON CONFLICT (name) DO NOTHING;
        """)

    op.execute(f"""
                INSERT INTO ticket_types (id, name)
                VALUES
                ('{uuid.uuid4()}', '{TicketTypeDefault.ACHIEVABILITY.value}')
                ON CONFLICT (name) DO NOTHING;
            """)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.execute(f"DELETE FROM user_roles WHERE name = '{UserRoleDefault.USER.value}'")
    op.execute(f"DELETE FROM ticket_statuses WHERE name IN ('{TicketStatusDefault.CREATED.value}',"
               f" '{TicketStatusDefault.IN_PROGRESS.value}', '{TicketStatusDefault.COMPLETED.value}',"
               f" '{TicketStatusDefault.FAILED.value}')")
    op.execute(f"DELETE FROM ticket_types WHERE name = '{TicketTypeDefault.ACHIEVABILITY.value}'")
    # ### end Alembic commands ###
