"""smtp_configs table

Revision ID: 0006_smtp
Revises: 0005_extensions
Create Date: 2026-03-27
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import UUID

revision = "0006_smtp"
down_revision = "0005_extensions"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.create_table(
        "smtp_configs",
        sa.Column("id", UUID(as_uuid=True), primary_key=True),
        sa.Column("company_id", UUID(as_uuid=True),
                  sa.ForeignKey("companies.id", ondelete="CASCADE"),
                  nullable=False),
        sa.Column("host", sa.String(255), nullable=False),
        sa.Column("port", sa.Integer, nullable=False, server_default="587"),
        sa.Column("use_tls", sa.Boolean, nullable=False, server_default="false"),
        sa.Column("use_starttls", sa.Boolean, nullable=False, server_default="true"),
        sa.Column("username", sa.String(255)),
        sa.Column("password_encrypted", sa.Text),
        sa.Column("from_email", sa.String(255), nullable=False),
        sa.Column("from_name", sa.String(255), nullable=False, server_default="TimeMaster"),
        sa.Column("is_enabled", sa.Boolean, nullable=False, server_default="true"),
        sa.UniqueConstraint("company_id", name="uq_smtp_configs_company"),
    )
    op.create_index("ix_smtp_configs_company_id", "smtp_configs", ["company_id"])


def downgrade() -> None:
    op.drop_index("ix_smtp_configs_company_id")
    op.drop_table("smtp_configs")
