"""phase-18: 고급 기능용 컬럼(메일 cc/thread, 발송 cc/bcc/첨부, 일정 반복/알림/참석자, 댓글 수정)

Revision ID: p18f6a7b8c9d0
Revises: p17e5f6a7b8c9
Create Date: 2026-06-16 10:00:00.000000

"""

from typing import Sequence, Union

import sqlalchemy as sa
import sqlmodel
from alembic import op

revision: str = "p18f6a7b8c9d0"
down_revision: Union[str, Sequence[str], None] = "p17e5f6a7b8c9"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None

S = sqlmodel.sql.sqltypes.AutoString


def upgrade() -> None:
    # 메일: 받은 메일 참조 + 대화(스레드) 묶기
    op.add_column("email", sa.Column("cc", S(), nullable=False, server_default=""))
    op.add_column("email", sa.Column("thread_id", S(), nullable=False, server_default=""))
    # 발송 메일: cc/bcc/첨부
    op.add_column("outbound_mail", sa.Column("cc", S(), nullable=False, server_default=""))
    op.add_column("outbound_mail", sa.Column("bcc", S(), nullable=False, server_default=""))
    op.add_column(
        "outbound_mail", sa.Column("attachments", sa.JSON(), nullable=False, server_default="[]")
    )
    # 일정: 반복/알림/참석자/내 RSVP
    op.add_column("cal_event", sa.Column("rrule", S(), nullable=False, server_default=""))
    op.add_column(
        "cal_event", sa.Column("reminders", sa.JSON(), nullable=False, server_default="[]")
    )
    op.add_column(
        "cal_event", sa.Column("attendees", sa.JSON(), nullable=False, server_default="[]")
    )
    op.add_column(
        "cal_event", sa.Column("response_status", S(), nullable=False, server_default="")
    )
    # 작업 댓글: 수정 시각
    op.add_column("task_comment", sa.Column("edited_at", sa.DateTime(), nullable=True))


def downgrade() -> None:
    op.drop_column("task_comment", "edited_at")
    op.drop_column("cal_event", "response_status")
    op.drop_column("cal_event", "attendees")
    op.drop_column("cal_event", "reminders")
    op.drop_column("cal_event", "rrule")
    op.drop_column("outbound_mail", "attachments")
    op.drop_column("outbound_mail", "bcc")
    op.drop_column("outbound_mail", "cc")
    op.drop_column("email", "thread_id")
    op.drop_column("email", "cc")
