"""Add organization settings table

Revision ID: 496c162975d7
Revises: 9194fb66b4ea
Create Date: 2025-01-09 00:02:47.484038

"""

from collections.abc import Sequence

import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "496c162975d7"
down_revision: str | None = "9194fb66b4ea"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "organization_settings",
        sa.Column("surrogate_id", sa.Integer(), nullable=False),
        sa.Column("owner_id", postgresql.UUID(as_uuid=True), nullable=False),
        sa.Column(
            "created_at",
            sa.TIMESTAMP(timezone=True),
            server_default=sa.text("now()"),
            nullable=False,
        ),
        sa.Column(
            "updated_at",
            sa.TIMESTAMP(timezone=True),
            server_default=sa.text("now()"),
            nullable=False,
        ),
        sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
        sa.Column("key", sa.String(), nullable=False),
        sa.Column("value", sa.LargeBinary(), nullable=False),
        sa.Column("value_type", sa.String(), nullable=False),
        sa.Column("is_encrypted", sa.Boolean(), nullable=False),
        sa.PrimaryKeyConstraint("surrogate_id", name="organization_settings_pkey"),
    )
    op.create_index(
        op.f("ix_organization_settings_id"),
        "organization_settings",
        ["id"],
        unique=True,
    )
    op.create_index(
        op.f("ix_organization_settings_key"),
        "organization_settings",
        ["key"],
        unique=True,
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(
        op.f("ix_organization_settings_key"), table_name="organization_settings"
    )
    op.drop_index(
        op.f("ix_organization_settings_id"), table_name="organization_settings"
    )
    op.drop_table("organization_settings")
    # ### end Alembic commands ###
