"""section profile catalog schema

Revision ID: 0003_section_profiles
Revises: 0002_projects
Create Date: 2026-06-11
"""
from __future__ import annotations

from alembic import op
import sqlalchemy as sa
from sqlalchemy import inspect


revision = "0003_section_profiles"
down_revision = "0002_projects"
branch_labels = None
depends_on = None


def upgrade() -> None:
    bind = op.get_bind()
    inspector = inspect(bind)
    if "section_profiles" in inspector.get_table_names():
        return

    op.create_table(
        "section_profiles",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("profile_key", sa.String(length=120), nullable=False),
        sa.Column("source_id", sa.String(length=80), nullable=False),
        sa.Column("source_name", sa.String(length=160), nullable=False),
        sa.Column("source_url", sa.Text(), nullable=True),
        sa.Column("source_revision", sa.String(length=80), nullable=True),
        sa.Column("standard_refs", sa.String(length=200), nullable=True),
        sa.Column("manufacturer", sa.String(length=80), nullable=True),
        sa.Column("steel_grade", sa.String(length=80), nullable=True),
        sa.Column("manufacturing_process", sa.String(length=40), nullable=False),
        sa.Column("process_label", sa.String(length=80), nullable=False),
        sa.Column("family", sa.String(length=40), nullable=False),
        sa.Column("family_label", sa.String(length=80), nullable=False),
        sa.Column("series", sa.String(length=40), nullable=False),
        sa.Column("series_label", sa.String(length=80), nullable=False),
        sa.Column("shape_type", sa.String(length=80), nullable=False),
        sa.Column("designation", sa.String(length=120), nullable=False),
        sa.Column("label", sa.String(length=120), nullable=False),
        sa.Column("available_by_order", sa.Boolean(), nullable=False),
        sa.Column("mass_kg_m", sa.Float(), nullable=False),
        sa.Column("area_m2", sa.Float(), nullable=False),
        sa.Column("ix_m4", sa.Float(), nullable=False),
        sa.Column("iy_m4", sa.Float(), nullable=False),
        sa.Column("j_m4", sa.Float(), nullable=False),
        sa.Column("d_m", sa.Float(), nullable=True),
        sa.Column("bf_m", sa.Float(), nullable=True),
        sa.Column("tw_m", sa.Float(), nullable=True),
        sa.Column("tf_m", sa.Float(), nullable=True),
        sa.Column("h_m", sa.Float(), nullable=True),
        sa.Column("d_prime_m", sa.Float(), nullable=True),
        sa.Column("wx_m3", sa.Float(), nullable=True),
        sa.Column("wy_m3", sa.Float(), nullable=True),
        sa.Column("rx_m", sa.Float(), nullable=True),
        sa.Column("ry_m", sa.Float(), nullable=True),
        sa.Column("zx_m3", sa.Float(), nullable=True),
        sa.Column("zy_m3", sa.Float(), nullable=True),
        sa.Column("cw_m6", sa.Float(), nullable=True),
        sa.Column("created_at", sa.DateTime(), server_default=sa.func.now(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.func.now(), nullable=False),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_section_profiles_profile_key"), "section_profiles", ["profile_key"], unique=True)
    op.create_index(op.f("ix_section_profiles_source_id"), "section_profiles", ["source_id"], unique=False)
    op.create_index(
        op.f("ix_section_profiles_manufacturing_process"),
        "section_profiles",
        ["manufacturing_process"],
        unique=False,
    )
    op.create_index(op.f("ix_section_profiles_family"), "section_profiles", ["family"], unique=False)
    op.create_index(op.f("ix_section_profiles_series"), "section_profiles", ["series"], unique=False)
    op.create_index(op.f("ix_section_profiles_designation"), "section_profiles", ["designation"], unique=False)


def downgrade() -> None:
    bind = op.get_bind()
    inspector = inspect(bind)
    if "section_profiles" not in inspector.get_table_names():
        return

    op.drop_index(op.f("ix_section_profiles_designation"), table_name="section_profiles")
    op.drop_index(op.f("ix_section_profiles_series"), table_name="section_profiles")
    op.drop_index(op.f("ix_section_profiles_family"), table_name="section_profiles")
    op.drop_index(op.f("ix_section_profiles_manufacturing_process"), table_name="section_profiles")
    op.drop_index(op.f("ix_section_profiles_source_id"), table_name="section_profiles")
    op.drop_index(op.f("ix_section_profiles_profile_key"), table_name="section_profiles")
    op.drop_table("section_profiles")
