"""phase-16: outbound_mail(발송 대기 메일) 테이블

Revision ID: p17e5f6a7b8c9
Revises: p16d4e5f6a7b8
Create Date: 2026-06-15 14:00:00.000000

"""

from typing import Sequence, Union

import sqlalchemy as sa
import sqlmodel
from alembic import op

revision: str = "p17e5f6a7b8c9"
down_revision: Union[str, Sequence[str], None] = "p16d4e5f6a7b8"
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.create_table(
        "outbound_mail",
        sa.Column("id", S(), nullable=False),
        sa.Column("approval_id", S(), nullable=False),
        sa.Column("connector_account_id", S(), nullable=True),
        sa.Column("mail_account", S(), nullable=False),
        sa.Column("to", S(), nullable=False),
        sa.Column("subject", S(), nullable=False),
        sa.Column("body", S(), nullable=False),
        sa.Column("status", S(), nullable=False),
        sa.Column("error_detail", S(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("sent_at", sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(["approval_id"], ["approval.id"]),
        sa.ForeignKeyConstraint(["connector_account_id"], ["connector_account.id"]),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index("ix_outbound_mail_approval_id", "outbound_mail", ["approval_id"])


def downgrade() -> None:
    op.drop_index("ix_outbound_mail_approval_id", table_name="outbound_mail")
    op.drop_table("outbound_mail")
