"""新增stmp相关配置

Revision ID: 6ff45db05863
Revises: 17ce752ed7cc
Create Date: 2026-03-20 09:39:23.544434

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '6ff45db05863'
down_revision: Union[str, None] = '17ce752ed7cc'
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! ###
    with op.batch_alter_table('projects', schema=None) as batch_op:
        batch_op.alter_column('cover_status',
               existing_type=sa.VARCHAR(length=20),
               server_default=None,
               existing_nullable=False)

    with op.batch_alter_table('settings', schema=None) as batch_op:
        batch_op.add_column(sa.Column('smtp_provider', sa.String(length=50), server_default='qq', nullable=False, comment='SMTP 提供商'))
        batch_op.add_column(sa.Column('smtp_host', sa.String(length=255), nullable=True, comment='SMTP 主机'))
        batch_op.add_column(sa.Column('smtp_port', sa.Integer(), server_default='465', nullable=False, comment='SMTP 端口'))
        batch_op.add_column(sa.Column('smtp_username', sa.String(length=255), nullable=True, comment='SMTP 用户名'))
        batch_op.add_column(sa.Column('smtp_password', sa.String(length=500), nullable=True, comment='SMTP 密码或授权码'))
        batch_op.add_column(sa.Column('smtp_use_tls', sa.Boolean(), server_default='0', nullable=False, comment='是否启用 TLS'))
        batch_op.add_column(sa.Column('smtp_use_ssl', sa.Boolean(), server_default='1', nullable=False, comment='是否启用 SSL'))
        batch_op.add_column(sa.Column('smtp_from_email', sa.String(length=255), nullable=True, comment='发件人邮箱'))
        batch_op.add_column(sa.Column('smtp_from_name', sa.String(length=255), server_default='MuMuAINovel', nullable=False, comment='发件人名称'))
        batch_op.add_column(sa.Column('email_auth_enabled', sa.Boolean(), server_default='1', nullable=False, comment='是否启用邮箱认证'))
        batch_op.add_column(sa.Column('email_register_enabled', sa.Boolean(), server_default='1', nullable=False, comment='是否启用邮箱注册'))
        batch_op.add_column(sa.Column('verification_code_ttl_minutes', sa.Integer(), server_default='10', nullable=False, comment='验证码有效期（分钟）'))
        batch_op.add_column(sa.Column('verification_resend_interval_seconds', sa.Integer(), server_default='60', nullable=False, comment='验证码重发间隔（秒）'))

    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('settings', schema=None) as batch_op:
        batch_op.drop_column('verification_resend_interval_seconds')
        batch_op.drop_column('verification_code_ttl_minutes')
        batch_op.drop_column('email_register_enabled')
        batch_op.drop_column('email_auth_enabled')
        batch_op.drop_column('smtp_from_name')
        batch_op.drop_column('smtp_from_email')
        batch_op.drop_column('smtp_use_ssl')
        batch_op.drop_column('smtp_use_tls')
        batch_op.drop_column('smtp_password')
        batch_op.drop_column('smtp_username')
        batch_op.drop_column('smtp_port')
        batch_op.drop_column('smtp_host')
        batch_op.drop_column('smtp_provider')

    with op.batch_alter_table('projects', schema=None) as batch_op:
        batch_op.alter_column('cover_status',
               existing_type=sa.VARCHAR(length=20),
               server_default=sa.text("'none'"),
               existing_nullable=False)

    # ### end Alembic commands ###