"""add courier working days schedule

Revision ID: d51c0018aa05
Revises: 6a8d1bc6e52d
Create Date: 2026-07-17 14:06:40.483072

"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = "d51c0018aa05"
down_revision: Union[str, None] = "6a8d1bc6e52d"
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! ###
    # NOTE: autogenerate also proposed op.drop_table('spatial_ref_sys') (a
    # PostGIS system table — dropping it would break PostGIS entirely) and
    # dropping refresh_tokens_token_hash_key/users_phone_key (pre-existing
    # unique-index-vs-named-constraint drift unrelated to this migration).
    # Both removed by hand — same drift called out in 42828b3f2eea. Also
    # added a server_default of every weekday so any existing
    # courier_profiles rows backfill to "every day" (a no-op restriction)
    # rather than failing the NOT NULL add or accidentally locking existing
    # couriers out of every day.
    op.add_column(
        "courier_profiles",
        sa.Column(
            "working_days",
            sa.JSON().with_variant(
                postgresql.JSONB(astext_type=sa.Text()), "postgresql"
            ),
            nullable=False,
            server_default="[0, 1, 2, 3, 4, 5, 6]",
        ),
    )
    op.alter_column("courier_profiles", "working_days", server_default=None)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column("courier_profiles", "working_days")
    # ### end Alembic commands ###
