﻿from __future__ import annotations

import math

from sqlalchemy import select
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import Session

from .models import SectionProfile


# MySQL FLOAT returns about six significant decimal digits for these legacy
# columns. This tolerance accepts only that storage round-trip; it is not a
# tolerance for changing catalog properties.
CATALOG_STORAGE_REL_TOLERANCE = 1e-5

GERDAU_W_SERIES_I_SOURCE = {
    "source_id": "gerdau_tabela_bitolas_2018",
    "source_name": "Tabela de Bitolas - Perfis Estruturais Gerdau",
    "source_url": "https://gsn.gerdau.com/sites/gsn_gerdau/files/downloadable_files/Tabela%20de%20Bitolas_1.pdf",
    "source_revision": "11/2018",
    "standard_refs": "ABNT NBR 15980:2011; ASTM A6/A6M",
    "manufacturer": "Gerdau",
    "steel_grade": "ASTM A572 Grau 50",
    "manufacturing_process": "hot_rolled",
    "process_label": "Perfis laminados",
    "family": "w",
    "family_label": "Perfil W",
    "series": "i",
    "series_label": "Serie I",
    "shape_type": "wide_flange_i",
}

GERDAU_W_SERIES_I_PROFILES = [
  {
    "profile_key": "GERDAU_W150X13.0",
    "designation": "W 150 x 13,0",
    "label": "W 150 x 13,0",
    "available_by_order": False,
    "mass_kg_m": 13.0,
    "d_m": 0.148,
    "bf_m": 0.1,
    "tw_m": 0.0043,
    "tf_m": 0.004900000000000001,
    "h_m": 0.138,
    "d_prime_m": 0.11800000000000001,
    "area_m2": 0.0016600000000000002,
    "ix_m4": 6.35e-06,
    "wx_m3": 8.58e-05,
    "rx_m": 0.0618,
    "zx_m3": 9.64e-05,
    "iy_m4": 8.2e-07,
    "wy_m3": 1.64e-05,
    "ry_m": 0.0222,
    "zy_m3": 2.55e-05,
    "j_m4": 1.72e-08,
    "cw_m6": 4.1809999999999995e-09
  },
  {
    "profile_key": "GERDAU_W150X18.0",
    "designation": "W 150 x 18,0",
    "label": "W 150 x 18,0",
    "available_by_order": False,
    "mass_kg_m": 18.0,
    "d_m": 0.153,
    "bf_m": 0.10200000000000001,
    "tw_m": 0.0058,
    "tf_m": 0.0070999999999999995,
    "h_m": 0.139,
    "d_prime_m": 0.11900000000000001,
    "area_m2": 0.00234,
    "ix_m4": 9.39e-06,
    "wx_m3": 0.0001228,
    "rx_m": 0.0634,
    "zx_m3": 0.0001394,
    "iy_m4": 1.26e-06,
    "wy_m3": 2.4699999999999997e-05,
    "ry_m": 0.0232,
    "zy_m3": 3.85e-05,
    "j_m4": 4.34e-08,
    "cw_m6": 6.683e-09
  },
  {
    "profile_key": "GERDAU_W150X24.0",
    "designation": "W 150 x 24,0",
    "label": "W 150 x 24,0",
    "available_by_order": False,
    "mass_kg_m": 24.0,
    "d_m": 0.16,
    "bf_m": 0.10200000000000001,
    "tw_m": 0.0066,
    "tf_m": 0.0103,
    "h_m": 0.139,
    "d_prime_m": 0.115,
    "area_m2": 0.00315,
    "ix_m4": 1.384e-05,
    "wx_m3": 0.000173,
    "rx_m": 0.0663,
    "zx_m3": 0.00019759999999999998,
    "iy_m4": 1.83e-06,
    "wy_m3": 3.59e-05,
    "ry_m": 0.024100000000000003,
    "zy_m3": 5.5799999999999994e-05,
    "j_m4": 1.108e-07,
    "cw_m6": 1.0206e-08
  },
  {
    "profile_key": "GERDAU_W200X15.0",
    "designation": "W 200 x 15,0",
    "label": "W 200 x 15,0",
    "available_by_order": False,
    "mass_kg_m": 15.0,
    "d_m": 0.2,
    "bf_m": 0.1,
    "tw_m": 0.0043,
    "tf_m": 0.005200000000000001,
    "h_m": 0.19,
    "d_prime_m": 0.17,
    "area_m2": 0.0019399999999999999,
    "ix_m4": 1.305e-05,
    "wx_m3": 0.0001305,
    "rx_m": 0.08199999999999999,
    "zx_m3": 0.0001479,
    "iy_m4": 8.7e-07,
    "wy_m3": 1.74e-05,
    "ry_m": 0.0212,
    "zy_m3": 2.73e-05,
    "j_m4": 2.0499999999999998e-08,
    "cw_m6": 8.221999999999999e-09
  },
  {
    "profile_key": "GERDAU_W200X19.3",
    "designation": "W 200 x 19,3",
    "label": "W 200 x 19,3",
    "available_by_order": False,
    "mass_kg_m": 19.3,
    "d_m": 0.203,
    "bf_m": 0.10200000000000001,
    "tw_m": 0.0058,
    "tf_m": 0.006500000000000001,
    "h_m": 0.19,
    "d_prime_m": 0.17,
    "area_m2": 0.00251,
    "ix_m4": 1.686e-05,
    "wx_m3": 0.0001661,
    "rx_m": 0.0819,
    "zx_m3": 0.0001906,
    "iy_m4": 1.1600000000000001e-06,
    "wy_m3": 2.27e-05,
    "ry_m": 0.021400000000000002,
    "zy_m3": 3.59e-05,
    "j_m4": 4.0199999999999996e-08,
    "cw_m6": 1.1098e-08
  },
  {
    "profile_key": "GERDAU_W200X22.5",
    "designation": "W 200 x 22,5",
    "label": "W 200 x 22,5",
    "available_by_order": False,
    "mass_kg_m": 22.5,
    "d_m": 0.20600000000000002,
    "bf_m": 0.10200000000000001,
    "tw_m": 0.006200000000000001,
    "tf_m": 0.008,
    "h_m": 0.19,
    "d_prime_m": 0.17,
    "area_m2": 0.0029000000000000002,
    "ix_m4": 2.029e-05,
    "wx_m3": 0.000197,
    "rx_m": 0.0837,
    "zx_m3": 0.00022549999999999998,
    "iy_m4": 1.42e-06,
    "wy_m3": 2.7899999999999997e-05,
    "ry_m": 0.0222,
    "zy_m3": 4.3899999999999996e-05,
    "j_m4": 6.18e-08,
    "cw_m6": 1.3868e-08
  },
  {
    "profile_key": "GERDAU_W200X26.6",
    "designation": "W 200 x 26,6",
    "label": "W 200 x 26,6",
    "available_by_order": False,
    "mass_kg_m": 26.6,
    "d_m": 0.20700000000000002,
    "bf_m": 0.133,
    "tw_m": 0.0058,
    "tf_m": 0.008400000000000001,
    "h_m": 0.19,
    "d_prime_m": 0.17,
    "area_m2": 0.0034200000000000003,
    "ix_m4": 2.611e-05,
    "wx_m3": 0.0002523,
    "rx_m": 0.0873,
    "zx_m3": 0.0002823,
    "iy_m4": 3.3e-06,
    "wy_m3": 4.96e-05,
    "ry_m": 0.031000000000000003,
    "zy_m3": 7.63e-05,
    "j_m4": 7.65e-08,
    "cw_m6": 3.2477e-08
  },
  {
    "profile_key": "GERDAU_W200X31.3",
    "designation": "W 200 x 31,3",
    "label": "W 200 x 31,3",
    "available_by_order": False,
    "mass_kg_m": 31.3,
    "d_m": 0.21,
    "bf_m": 0.134,
    "tw_m": 0.0064,
    "tf_m": 0.010199999999999999,
    "h_m": 0.19,
    "d_prime_m": 0.17,
    "area_m2": 0.00403,
    "ix_m4": 3.168e-05,
    "wx_m3": 0.00030169999999999996,
    "rx_m": 0.0886,
    "zx_m3": 0.0003386,
    "iy_m4": 4.1e-06,
    "wy_m3": 6.12e-05,
    "ry_m": 0.0319,
    "zy_m3": 9.4e-05,
    "j_m4": 1.259e-07,
    "cw_m6": 4.0822e-08
  },
  {
    "profile_key": "GERDAU_W250X17.9",
    "designation": "W 250 x 17,9",
    "label": "W 250 x 17,9",
    "available_by_order": False,
    "mass_kg_m": 17.9,
    "d_m": 0.251,
    "bf_m": 0.101,
    "tw_m": 0.0048,
    "tf_m": 0.0053,
    "h_m": 0.24,
    "d_prime_m": 0.22,
    "area_m2": 0.0023100000000000004,
    "ix_m4": 2.291e-05,
    "wx_m3": 0.0001826,
    "rx_m": 0.09960000000000001,
    "zx_m3": 0.00021099999999999998,
    "iy_m4": 9.1e-07,
    "wy_m3": 1.81e-05,
    "ry_m": 0.0199,
    "zy_m3": 2.88e-05,
    "j_m4": 2.5400000000000002e-08,
    "cw_m6": 1.3735e-08
  },
  {
    "profile_key": "GERDAU_W250X22.3",
    "designation": "W 250 x 22,3",
    "label": "W 250 x 22,3",
    "available_by_order": False,
    "mass_kg_m": 22.3,
    "d_m": 0.254,
    "bf_m": 0.10200000000000001,
    "tw_m": 0.0058,
    "tf_m": 0.006900000000000001,
    "h_m": 0.24,
    "d_prime_m": 0.22,
    "area_m2": 0.00289,
    "ix_m4": 2.939e-05,
    "wx_m3": 0.0002314,
    "rx_m": 0.1009,
    "zx_m3": 0.0002677,
    "iy_m4": 1.23e-06,
    "wy_m3": 2.41e-05,
    "ry_m": 0.0206,
    "zy_m3": 3.84e-05,
    "j_m4": 4.77e-08,
    "cw_m6": 1.8629e-08
  },
  {
    "profile_key": "GERDAU_W250X25.3",
    "designation": "W 250 x 25,3",
    "label": "W 250 x 25,3",
    "available_by_order": False,
    "mass_kg_m": 25.3,
    "d_m": 0.257,
    "bf_m": 0.10200000000000001,
    "tw_m": 0.0060999999999999995,
    "tf_m": 0.008400000000000001,
    "h_m": 0.24,
    "d_prime_m": 0.22,
    "area_m2": 0.0032600000000000003,
    "ix_m4": 3.473e-05,
    "wx_m3": 0.00027019999999999995,
    "rx_m": 0.10310000000000001,
    "zx_m3": 0.0003111,
    "iy_m4": 1.4900000000000001e-06,
    "wy_m3": 2.93e-05,
    "ry_m": 0.021400000000000002,
    "zy_m3": 4.6399999999999996e-05,
    "j_m4": 7.06e-08,
    "cw_m6": 2.2955e-08
  },
  {
    "profile_key": "GERDAU_W250X28.4",
    "designation": "W 250 x 28,4",
    "label": "W 250 x 28,4",
    "available_by_order": False,
    "mass_kg_m": 28.4,
    "d_m": 0.26,
    "bf_m": 0.10200000000000001,
    "tw_m": 0.0064,
    "tf_m": 0.01,
    "h_m": 0.24,
    "d_prime_m": 0.22,
    "area_m2": 0.0036600000000000005,
    "ix_m4": 4.046e-05,
    "wx_m3": 0.0003112,
    "rx_m": 0.1051,
    "zx_m3": 0.0003573,
    "iy_m4": 1.7800000000000001e-06,
    "wy_m3": 3.48e-05,
    "ry_m": 0.022000000000000002,
    "zy_m3": 5.489999999999999e-05,
    "j_m4": 1.034e-07,
    "cw_m6": 2.7636e-08
  },
  {
    "profile_key": "GERDAU_W250X32.7",
    "designation": "W 250 x 32,7",
    "label": "W 250 x 32,7",
    "available_by_order": False,
    "mass_kg_m": 32.7,
    "d_m": 0.258,
    "bf_m": 0.146,
    "tw_m": 0.0060999999999999995,
    "tf_m": 0.0091,
    "h_m": 0.24,
    "d_prime_m": 0.22,
    "area_m2": 0.00421,
    "ix_m4": 4.937e-05,
    "wx_m3": 0.0003827,
    "rx_m": 0.10830000000000001,
    "zx_m3": 0.0004285,
    "iy_m4": 4.7300000000000005e-06,
    "wy_m3": 6.479999999999999e-05,
    "ry_m": 0.0335,
    "zy_m3": 9.97e-05,
    "j_m4": 1.044e-07,
    "cw_m6": 7.3104e-08
  },
  {
    "profile_key": "GERDAU_W250X38.5",
    "designation": "W 250 x 38,5",
    "label": "W 250 x 38,5",
    "available_by_order": False,
    "mass_kg_m": 38.5,
    "d_m": 0.262,
    "bf_m": 0.147,
    "tw_m": 0.0066,
    "tf_m": 0.0112,
    "h_m": 0.24,
    "d_prime_m": 0.22,
    "area_m2": 0.00496,
    "ix_m4": 6.0570000000000005e-05,
    "wx_m3": 0.00046239999999999996,
    "rx_m": 0.11050000000000001,
    "zx_m3": 0.0005177999999999999,
    "iy_m4": 5.94e-06,
    "wy_m3": 8.08e-05,
    "ry_m": 0.0346,
    "zy_m3": 0.00012409999999999998,
    "j_m4": 1.7629999999999998e-07,
    "cw_m6": 9.3242e-08
  },
  {
    "profile_key": "GERDAU_W250X44.8",
    "designation": "W 250 x 44,8",
    "label": "W 250 x 44,8",
    "available_by_order": False,
    "mass_kg_m": 44.8,
    "d_m": 0.266,
    "bf_m": 0.148,
    "tw_m": 0.0076,
    "tf_m": 0.013000000000000001,
    "h_m": 0.24,
    "d_prime_m": 0.22,
    "area_m2": 0.00576,
    "ix_m4": 7.158e-05,
    "wx_m3": 0.0005382000000000001,
    "rx_m": 0.1115,
    "zx_m3": 0.0006062999999999999,
    "iy_m4": 7.04e-06,
    "wy_m3": 9.51e-05,
    "ry_m": 0.035,
    "zy_m3": 0.0001464,
    "j_m4": 2.714e-07,
    "cw_m6": 1.12398e-07
  },
  {
    "profile_key": "GERDAU_W310X21.0",
    "designation": "W 310 x 21,0",
    "label": "W 310 x 21,0",
    "available_by_order": False,
    "mass_kg_m": 21.0,
    "d_m": 0.303,
    "bf_m": 0.101,
    "tw_m": 0.0050999999999999995,
    "tf_m": 0.0057,
    "h_m": 0.292,
    "d_prime_m": 0.272,
    "area_m2": 0.00272,
    "ix_m4": 3.776e-05,
    "wx_m3": 0.0002492,
    "rx_m": 0.1177,
    "zx_m3": 0.00029189999999999994,
    "iy_m4": 9.8e-07,
    "wy_m3": 1.95e-05,
    "ry_m": 0.019,
    "zy_m3": 3.14e-05,
    "j_m4": 3.27e-08,
    "cw_m6": 2.1628e-08
  },
  {
    "profile_key": "GERDAU_W310X23.8",
    "designation": "W 310 x 23,8",
    "label": "W 310 x 23,8",
    "available_by_order": False,
    "mass_kg_m": 23.8,
    "d_m": 0.305,
    "bf_m": 0.101,
    "tw_m": 0.0056,
    "tf_m": 0.0067,
    "h_m": 0.292,
    "d_prime_m": 0.272,
    "area_m2": 0.0030700000000000002,
    "ix_m4": 4.346e-05,
    "wx_m3": 0.000285,
    "rx_m": 0.1189,
    "zx_m3": 0.00033319999999999997,
    "iy_m4": 1.1600000000000001e-06,
    "wy_m3": 2.2899999999999998e-05,
    "ry_m": 0.0194,
    "zy_m3": 3.6899999999999996e-05,
    "j_m4": 4.6500000000000006e-08,
    "cw_m6": 2.5594e-08
  },
  {
    "profile_key": "GERDAU_W310X28.3",
    "designation": "W 310 x 28,3",
    "label": "W 310 x 28,3",
    "available_by_order": False,
    "mass_kg_m": 28.3,
    "d_m": 0.309,
    "bf_m": 0.10200000000000001,
    "tw_m": 0.006,
    "tf_m": 0.0089,
    "h_m": 0.291,
    "d_prime_m": 0.271,
    "area_m2": 0.00365,
    "ix_m4": 5.5e-05,
    "wx_m3": 0.000356,
    "rx_m": 0.12279999999999999,
    "zx_m3": 0.000412,
    "iy_m4": 1.5800000000000001e-06,
    "wy_m3": 3.1e-05,
    "ry_m": 0.020800000000000003,
    "zy_m3": 4.9399999999999995e-05,
    "j_m4": 8.14e-08,
    "cw_m6": 3.5441e-08
  },
  {
    "profile_key": "GERDAU_W310X32.7",
    "designation": "W 310 x 32,7",
    "label": "W 310 x 32,7",
    "available_by_order": False,
    "mass_kg_m": 32.7,
    "d_m": 0.313,
    "bf_m": 0.10200000000000001,
    "tw_m": 0.0066,
    "tf_m": 0.0108,
    "h_m": 0.291,
    "d_prime_m": 0.271,
    "area_m2": 0.00421,
    "ix_m4": 6.57e-05,
    "wx_m3": 0.0004198,
    "rx_m": 0.12490000000000001,
    "zx_m3": 0.0004853,
    "iy_m4": 1.9200000000000003e-06,
    "wy_m3": 3.76e-05,
    "ry_m": 0.0213,
    "zy_m3": 5.98e-05,
    "j_m4": 1.291e-07,
    "cw_m6": 4.3612e-08
  },
  {
    "profile_key": "GERDAU_W310X38.7",
    "designation": "W 310 x 38,7",
    "label": "W 310 x 38,7",
    "available_by_order": False,
    "mass_kg_m": 38.7,
    "d_m": 0.31,
    "bf_m": 0.165,
    "tw_m": 0.0058,
    "tf_m": 0.0097,
    "h_m": 0.291,
    "d_prime_m": 0.271,
    "area_m2": 0.0049700000000000005,
    "ix_m4": 8.581000000000001e-05,
    "wx_m3": 0.0005536,
    "rx_m": 0.13140000000000002,
    "zx_m3": 0.0006154,
    "iy_m4": 7.27e-06,
    "wy_m3": 8.809999999999999e-05,
    "ry_m": 0.0382,
    "zy_m3": 0.0001349,
    "j_m4": 1.32e-07,
    "cw_m6": 1.63728e-07
  },
  {
    "profile_key": "GERDAU_W310X44.5",
    "designation": "W 310 x 44,5",
    "label": "W 310 x 44,5",
    "available_by_order": False,
    "mass_kg_m": 44.5,
    "d_m": 0.313,
    "bf_m": 0.166,
    "tw_m": 0.0066,
    "tf_m": 0.0112,
    "h_m": 0.291,
    "d_prime_m": 0.271,
    "area_m2": 0.00572,
    "ix_m4": 9.997e-05,
    "wx_m3": 0.0006387999999999999,
    "rx_m": 0.1322,
    "zx_m3": 0.0007127999999999999,
    "iy_m4": 8.55e-06,
    "wy_m3": 0.000103,
    "ry_m": 0.038700000000000005,
    "zy_m3": 0.000158,
    "j_m4": 1.99e-07,
    "cw_m6": 1.94433e-07
  },
  {
    "profile_key": "GERDAU_W310X52.0",
    "designation": "W 310 x 52,0",
    "label": "W 310 x 52,0",
    "available_by_order": False,
    "mass_kg_m": 52.0,
    "d_m": 0.317,
    "bf_m": 0.167,
    "tw_m": 0.0076,
    "tf_m": 0.0132,
    "h_m": 0.291,
    "d_prime_m": 0.271,
    "area_m2": 0.0067,
    "ix_m4": 0.00011909,
    "wx_m3": 0.0007513999999999999,
    "rx_m": 0.1333,
    "zx_m3": 0.0008424999999999999,
    "iy_m4": 1.026e-05,
    "wy_m3": 0.0001229,
    "ry_m": 0.0391,
    "zy_m3": 0.0001888,
    "j_m4": 3.1809999999999997e-07,
    "cw_m6": 2.36422e-07
  },
  {
    "profile_key": "GERDAU_W310X60.0",
    "designation": "W 310 x 60,0",
    "label": "W 310 x 60,0",
    "available_by_order": True,
    "mass_kg_m": 60.0,
    "d_m": 0.303,
    "bf_m": 0.203,
    "tw_m": 0.0075,
    "tf_m": 0.0131,
    "h_m": 0.277,
    "d_prime_m": 0.245,
    "area_m2": 0.00761,
    "ix_m4": 0.00012908,
    "wx_m3": 0.000852,
    "rx_m": 0.1302,
    "zx_m3": 0.0009442999999999999,
    "iy_m4": 1.829e-05,
    "wy_m3": 0.0001802,
    "ry_m": 0.049,
    "zy_m3": 0.00027539999999999997,
    "j_m4": 4.046e-07,
    "cw_m6": 3.83747e-07
  },
  {
    "profile_key": "GERDAU_W310X67.0",
    "designation": "W 310 x 67,0",
    "label": "W 310 x 67,0",
    "available_by_order": True,
    "mass_kg_m": 67.0,
    "d_m": 0.306,
    "bf_m": 0.20400000000000001,
    "tw_m": 0.0085,
    "tf_m": 0.0146,
    "h_m": 0.277,
    "d_prime_m": 0.245,
    "area_m2": 0.00853,
    "ix_m4": 0.00014559,
    "wx_m3": 0.0009515,
    "rx_m": 0.1306,
    "zx_m3": 0.0010604,
    "iy_m4": 2.069e-05,
    "wy_m3": 0.0002028,
    "ry_m": 0.0492,
    "zy_m3": 0.0003105,
    "j_m4": 5.535e-07,
    "cw_m6": 4.38542e-07
  },
  {
    "profile_key": "GERDAU_W310X74.0",
    "designation": "W 310 x 74,0",
    "label": "W 310 x 74,0",
    "available_by_order": True,
    "mass_kg_m": 74.0,
    "d_m": 0.31,
    "bf_m": 0.20500000000000002,
    "tw_m": 0.0094,
    "tf_m": 0.016300000000000002,
    "h_m": 0.277,
    "d_prime_m": 0.245,
    "area_m2": 0.00951,
    "ix_m4": 0.00016501,
    "wx_m3": 0.0010646,
    "rx_m": 0.1317,
    "zx_m3": 0.001192,
    "iy_m4": 2.344e-05,
    "wy_m3": 0.00022869999999999998,
    "ry_m": 0.0496,
    "zy_m3": 0.0003505,
    "j_m4": 7.551000000000001e-07,
    "cw_m6": 5.04715e-07
  },
  {
    "profile_key": "GERDAU_W360X32.9",
    "designation": "W 360 x 32,9",
    "label": "W 360 x 32,9",
    "available_by_order": False,
    "mass_kg_m": 32.9,
    "d_m": 0.34900000000000003,
    "bf_m": 0.127,
    "tw_m": 0.0058,
    "tf_m": 0.0085,
    "h_m": 0.332,
    "d_prime_m": 0.308,
    "area_m2": 0.00421,
    "ix_m4": 8.358e-05,
    "wx_m3": 0.000479,
    "rx_m": 0.1409,
    "zx_m3": 0.0005476,
    "iy_m4": 2.91e-06,
    "wy_m3": 4.59e-05,
    "ry_m": 0.0263,
    "zy_m3": 7.2e-05,
    "j_m4": 9.15e-08,
    "cw_m6": 8.4111e-08
  },
  {
    "profile_key": "GERDAU_W360X39.0",
    "designation": "W 360 x 39,0",
    "label": "W 360 x 39,0",
    "available_by_order": False,
    "mass_kg_m": 39.0,
    "d_m": 0.353,
    "bf_m": 0.128,
    "tw_m": 0.006500000000000001,
    "tf_m": 0.0107,
    "h_m": 0.332,
    "d_prime_m": 0.308,
    "area_m2": 0.00502,
    "ix_m4": 0.00010331,
    "wx_m3": 0.0005853,
    "rx_m": 0.1435,
    "zx_m3": 0.0006677,
    "iy_m4": 3.75e-06,
    "wy_m3": 5.86e-05,
    "ry_m": 0.0273,
    "zy_m3": 9.19e-05,
    "j_m4": 1.583e-07,
    "cw_m6": 1.09551e-07
  },
  {
    "profile_key": "GERDAU_W360X44.6",
    "designation": "W 360 x 44,6",
    "label": "W 360 x 44,6",
    "available_by_order": False,
    "mass_kg_m": 44.6,
    "d_m": 0.352,
    "bf_m": 0.171,
    "tw_m": 0.006900000000000001,
    "tf_m": 0.009800000000000001,
    "h_m": 0.332,
    "d_prime_m": 0.308,
    "area_m2": 0.005770000000000001,
    "ix_m4": 0.00012258,
    "wx_m3": 0.0006965,
    "rx_m": 0.1458,
    "zx_m3": 0.0007842999999999999,
    "iy_m4": 8.18e-06,
    "wy_m3": 9.57e-05,
    "ry_m": 0.037700000000000004,
    "zy_m3": 0.000148,
    "j_m4": 1.67e-07,
    "cw_m6": 2.39091e-07
  },
  {
    "profile_key": "GERDAU_W360X51.0",
    "designation": "W 360 x 51,0",
    "label": "W 360 x 51,0",
    "available_by_order": False,
    "mass_kg_m": 51.0,
    "d_m": 0.355,
    "bf_m": 0.171,
    "tw_m": 0.007200000000000001,
    "tf_m": 0.0116,
    "h_m": 0.332,
    "d_prime_m": 0.308,
    "area_m2": 0.00648,
    "ix_m4": 0.00014222,
    "wx_m3": 0.0008012,
    "rx_m": 0.1481,
    "zx_m3": 0.0008994999999999999,
    "iy_m4": 9.68e-06,
    "wy_m3": 0.00011329999999999999,
    "ry_m": 0.038700000000000005,
    "zy_m3": 0.0001747,
    "j_m4": 2.465e-07,
    "cw_m6": 2.84994e-07
  },
  {
    "profile_key": "GERDAU_W360X58",
    "designation": "W 360 x 58",
    "label": "W 360 x 58",
    "available_by_order": True,
    "mass_kg_m": 58.0,
    "d_m": 0.358,
    "bf_m": 0.17200000000000001,
    "tw_m": 0.0079,
    "tf_m": 0.0131,
    "h_m": 0.332,
    "d_prime_m": 0.308,
    "area_m2": 0.00725,
    "ix_m4": 0.00016143,
    "wx_m3": 0.0009017999999999999,
    "rx_m": 0.1492,
    "zx_m3": 0.0010148,
    "iy_m4": 1.113e-05,
    "wy_m3": 0.0001294,
    "ry_m": 0.0392,
    "zy_m3": 0.0001998,
    "j_m4": 3.4450000000000005e-07,
    "cw_m6": 3.30394e-07
  },
  {
    "profile_key": "GERDAU_W360X64.0",
    "designation": "W 360 x 64,0",
    "label": "W 360 x 64,0",
    "available_by_order": False,
    "mass_kg_m": 64.0,
    "d_m": 0.34700000000000003,
    "bf_m": 0.203,
    "tw_m": 0.0077,
    "tf_m": 0.0135,
    "h_m": 0.32,
    "d_prime_m": 0.28800000000000003,
    "area_m2": 0.00817,
    "ix_m4": 0.0001789,
    "wx_m3": 0.0010310999999999999,
    "rx_m": 0.14800000000000002,
    "zx_m3": 0.0011455,
    "iy_m4": 1.885e-05,
    "wy_m3": 0.0001857,
    "ry_m": 0.048,
    "zy_m3": 0.0002845,
    "j_m4": 4.4570000000000003e-07,
    "cw_m6": 5.233619999999999e-07
  },
  {
    "profile_key": "GERDAU_W360X72.0",
    "designation": "W 360 x 72,0",
    "label": "W 360 x 72,0",
    "available_by_order": False,
    "mass_kg_m": 72.0,
    "d_m": 0.35000000000000003,
    "bf_m": 0.20400000000000001,
    "tw_m": 0.0086,
    "tf_m": 0.0151,
    "h_m": 0.32,
    "d_prime_m": 0.28800000000000003,
    "area_m2": 0.009130000000000001,
    "ix_m4": 0.00020169,
    "wx_m3": 0.0011524999999999999,
    "rx_m": 0.1486,
    "zx_m3": 0.0012859,
    "iy_m4": 2.1400000000000002e-05,
    "wy_m3": 0.0002098,
    "ry_m": 0.0484,
    "zy_m3": 0.0003218,
    "j_m4": 6.118e-07,
    "cw_m6": 5.990819999999999e-07
  },
  {
    "profile_key": "GERDAU_W360X79.0",
    "designation": "W 360 x 79,0",
    "label": "W 360 x 79,0",
    "available_by_order": False,
    "mass_kg_m": 79.0,
    "d_m": 0.354,
    "bf_m": 0.20500000000000002,
    "tw_m": 0.0094,
    "tf_m": 0.016800000000000002,
    "h_m": 0.32,
    "d_prime_m": 0.28800000000000003,
    "area_m2": 0.01012,
    "ix_m4": 0.00022713,
    "wx_m3": 0.0012832,
    "rx_m": 0.14980000000000002,
    "zx_m3": 0.001437,
    "iy_m4": 2.416e-05,
    "wy_m3": 0.00023569999999999998,
    "ry_m": 0.0489,
    "zy_m3": 0.00036189999999999996,
    "j_m4": 8.241e-07,
    "cw_m6": 6.85701e-07
  },
  {
    "profile_key": "GERDAU_W410X38.8",
    "designation": "W 410 x 38,8",
    "label": "W 410 x 38,8",
    "available_by_order": False,
    "mass_kg_m": 38.8,
    "d_m": 0.399,
    "bf_m": 0.14,
    "tw_m": 0.0064,
    "tf_m": 0.0088,
    "h_m": 0.381,
    "d_prime_m": 0.357,
    "area_m2": 0.00503,
    "ix_m4": 0.00012777,
    "wx_m3": 0.0006405,
    "rx_m": 0.1594,
    "zx_m3": 0.0007367999999999999,
    "iy_m4": 4.04e-06,
    "wy_m3": 5.77e-05,
    "ry_m": 0.028300000000000002,
    "zy_m3": 9.09e-05,
    "j_m4": 1.169e-07,
    "cw_m6": 1.5318999999999998e-07
  },
  {
    "profile_key": "GERDAU_W410X46.1",
    "designation": "W 410 x 46,1",
    "label": "W 410 x 46,1",
    "available_by_order": False,
    "mass_kg_m": 46.1,
    "d_m": 0.403,
    "bf_m": 0.14,
    "tw_m": 0.007,
    "tf_m": 0.0112,
    "h_m": 0.381,
    "d_prime_m": 0.357,
    "area_m2": 0.005920000000000001,
    "ix_m4": 0.0001569,
    "wx_m3": 0.0007787,
    "rx_m": 0.1627,
    "zx_m3": 0.0008911,
    "iy_m4": 5.14e-06,
    "wy_m3": 7.340000000000001e-05,
    "ry_m": 0.029500000000000002,
    "zy_m3": 0.0001152,
    "j_m4": 2.0059999999999998e-07,
    "cw_m6": 1.96571e-07
  },
  {
    "profile_key": "GERDAU_W410X53.0",
    "designation": "W 410 x 53,0",
    "label": "W 410 x 53,0",
    "available_by_order": False,
    "mass_kg_m": 53.0,
    "d_m": 0.403,
    "bf_m": 0.177,
    "tw_m": 0.0075,
    "tf_m": 0.0109,
    "h_m": 0.381,
    "d_prime_m": 0.357,
    "area_m2": 0.006840000000000001,
    "ix_m4": 0.00018734,
    "wx_m3": 0.0009297,
    "rx_m": 0.1655,
    "zx_m3": 0.0010522,
    "iy_m4": 1.009e-05,
    "wy_m3": 0.00011399999999999999,
    "ry_m": 0.0384,
    "zy_m3": 0.0001769,
    "j_m4": 2.338e-07,
    "cw_m6": 3.8719399999999997e-07
  },
  {
    "profile_key": "GERDAU_W410X60.0",
    "designation": "W 410 x 60,0",
    "label": "W 410 x 60,0",
    "available_by_order": False,
    "mass_kg_m": 60.0,
    "d_m": 0.40700000000000003,
    "bf_m": 0.178,
    "tw_m": 0.0077,
    "tf_m": 0.0128,
    "h_m": 0.381,
    "d_prime_m": 0.357,
    "area_m2": 0.007620000000000001,
    "ix_m4": 0.00021707,
    "wx_m3": 0.0010667,
    "rx_m": 0.1688,
    "zx_m3": 0.0012014999999999999,
    "iy_m4": 1.205e-05,
    "wy_m3": 0.0001354,
    "ry_m": 0.0398,
    "zy_m3": 0.0002092,
    "j_m4": 3.378e-07,
    "cw_m6": 4.6740399999999997e-07
  },
  {
    "profile_key": "GERDAU_W410X67.0",
    "designation": "W 410 x 67,0",
    "label": "W 410 x 67,0",
    "available_by_order": True,
    "mass_kg_m": 67.0,
    "d_m": 0.41000000000000003,
    "bf_m": 0.179,
    "tw_m": 0.0088,
    "tf_m": 0.014400000000000001,
    "h_m": 0.381,
    "d_prime_m": 0.357,
    "area_m2": 0.00863,
    "ix_m4": 0.00024678,
    "wx_m3": 0.0012037999999999999,
    "rx_m": 0.1691,
    "zx_m3": 0.0013627,
    "iy_m4": 1.379e-05,
    "wy_m3": 0.00015409999999999998,
    "ry_m": 0.04,
    "zy_m3": 0.00023899999999999998,
    "j_m4": 4.811e-07,
    "cw_m6": 5.38546e-07
  },
  {
    "profile_key": "GERDAU_W410X75.0",
    "designation": "W 410 x 75,0",
    "label": "W 410 x 75,0",
    "available_by_order": True,
    "mass_kg_m": 75.0,
    "d_m": 0.41300000000000003,
    "bf_m": 0.18,
    "tw_m": 0.0097,
    "tf_m": 0.016,
    "h_m": 0.381,
    "d_prime_m": 0.357,
    "area_m2": 0.00958,
    "ix_m4": 0.00027616,
    "wx_m3": 0.0013372999999999998,
    "rx_m": 0.1698,
    "zx_m3": 0.0015186,
    "iy_m4": 1.559e-05,
    "wy_m3": 0.00017319999999999998,
    "ry_m": 0.0403,
    "zy_m3": 0.00026910000000000004,
    "j_m4": 6.521e-07,
    "cw_m6": 6.12784e-07
  },
  {
    "profile_key": "GERDAU_W410X85.0",
    "designation": "W 410 x 85,0",
    "label": "W 410 x 85,0",
    "available_by_order": True,
    "mass_kg_m": 85.0,
    "d_m": 0.417,
    "bf_m": 0.181,
    "tw_m": 0.0109,
    "tf_m": 0.0182,
    "h_m": 0.381,
    "d_prime_m": 0.357,
    "area_m2": 0.01086,
    "ix_m4": 0.00031658,
    "wx_m3": 0.0015184,
    "rx_m": 0.17070000000000002,
    "zx_m3": 0.0017316999999999999,
    "iy_m4": 1.804e-05,
    "wy_m3": 0.0001993,
    "ry_m": 0.0408,
    "zy_m3": 0.00031039999999999996,
    "j_m4": 9.448e-07,
    "cw_m6": 7.15165e-07
  },
  {
    "profile_key": "GERDAU_W460X52.0",
    "designation": "W 460 x 52,0",
    "label": "W 460 x 52,0",
    "available_by_order": False,
    "mass_kg_m": 52.0,
    "d_m": 0.45,
    "bf_m": 0.152,
    "tw_m": 0.0076,
    "tf_m": 0.0108,
    "h_m": 0.428,
    "d_prime_m": 0.404,
    "area_m2": 0.00666,
    "ix_m4": 0.00021370000000000002,
    "wx_m3": 0.0009497999999999999,
    "rx_m": 0.1791,
    "zx_m3": 0.0010959000000000001,
    "iy_m4": 6.34e-06,
    "wy_m3": 8.35e-05,
    "ry_m": 0.0309,
    "zy_m3": 0.00013169999999999998,
    "j_m4": 2.1789999999999999e-07,
    "cw_m6": 3.04837e-07
  },
  {
    "profile_key": "GERDAU_W460X60.0",
    "designation": "W 460 x 60,0",
    "label": "W 460 x 60,0",
    "available_by_order": False,
    "mass_kg_m": 60.0,
    "d_m": 0.455,
    "bf_m": 0.153,
    "tw_m": 0.008,
    "tf_m": 0.013300000000000001,
    "h_m": 0.428,
    "d_prime_m": 0.404,
    "area_m2": 0.007620000000000001,
    "ix_m4": 0.00025652,
    "wx_m3": 0.0011275999999999999,
    "rx_m": 0.18350000000000002,
    "zx_m3": 0.0012920999999999998,
    "iy_m4": 7.96e-06,
    "wy_m3": 0.0001041,
    "ry_m": 0.0323,
    "zy_m3": 0.0001634,
    "j_m4": 3.46e-07,
    "cw_m6": 3.8723e-07
  },
  {
    "profile_key": "GERDAU_W460X68.0",
    "designation": "W 460 x 68,0",
    "label": "W 460 x 68,0",
    "available_by_order": True,
    "mass_kg_m": 68.0,
    "d_m": 0.459,
    "bf_m": 0.154,
    "tw_m": 0.0091,
    "tf_m": 0.0154,
    "h_m": 0.428,
    "d_prime_m": 0.404,
    "area_m2": 0.00876,
    "ix_m4": 0.00029851,
    "wx_m3": 0.0013007,
    "rx_m": 0.18460000000000001,
    "zx_m3": 0.0014954,
    "iy_m4": 9.41e-06,
    "wy_m3": 0.0001222,
    "ry_m": 0.032799999999999996,
    "zy_m3": 0.0001924,
    "j_m4": 5.229e-07,
    "cw_m6": 4.61163e-07
  },
  {
    "profile_key": "GERDAU_W460X74.0",
    "designation": "W 460 x 74,0",
    "label": "W 460 x 74,0",
    "available_by_order": False,
    "mass_kg_m": 74.0,
    "d_m": 0.457,
    "bf_m": 0.19,
    "tw_m": 0.009000000000000001,
    "tf_m": 0.0145,
    "h_m": 0.428,
    "d_prime_m": 0.404,
    "area_m2": 0.00949,
    "ix_m4": 0.00033415,
    "wx_m3": 0.0014624,
    "rx_m": 0.1877,
    "zx_m3": 0.0016574,
    "iy_m4": 1.6610000000000002e-05,
    "wy_m3": 0.0001748,
    "ry_m": 0.0418,
    "zy_m3": 0.0002713,
    "j_m4": 5.297e-07,
    "cw_m6": 8.11417e-07
  },
  {
    "profile_key": "GERDAU_W460X82.0",
    "designation": "W 460 x 82,0",
    "label": "W 460 x 82,0",
    "available_by_order": False,
    "mass_kg_m": 82.0,
    "d_m": 0.46,
    "bf_m": 0.191,
    "tw_m": 0.0099,
    "tf_m": 0.016,
    "h_m": 0.428,
    "d_prime_m": 0.404,
    "area_m2": 0.01047,
    "ix_m4": 0.00037157,
    "wx_m3": 0.0016155,
    "rx_m": 0.1884,
    "zx_m3": 0.0018364,
    "iy_m4": 1.862e-05,
    "wy_m3": 0.000195,
    "ry_m": 0.0422,
    "zy_m3": 0.0003033,
    "j_m4": 7.062e-07,
    "cw_m6": 9.157449999999999e-07
  },
  {
    "profile_key": "GERDAU_W460X89.0",
    "designation": "W 460 x 89,0",
    "label": "W 460 x 89,0",
    "available_by_order": False,
    "mass_kg_m": 89.0,
    "d_m": 0.463,
    "bf_m": 0.192,
    "tw_m": 0.0105,
    "tf_m": 0.0177,
    "h_m": 0.428,
    "d_prime_m": 0.404,
    "area_m2": 0.01141,
    "ix_m4": 0.00041105,
    "wx_m3": 0.0017755999999999998,
    "rx_m": 0.1898,
    "zx_m3": 0.0020194,
    "iy_m4": 2.093e-05,
    "wy_m3": 0.00021799999999999999,
    "ry_m": 0.042800000000000005,
    "zy_m3": 0.000339,
    "j_m4": 9.248999999999999e-07,
    "cw_m6": 1.035073e-06
  },
  {
    "profile_key": "GERDAU_W460X97.0",
    "designation": "W 460 x 97,0",
    "label": "W 460 x 97,0",
    "available_by_order": True,
    "mass_kg_m": 97.0,
    "d_m": 0.466,
    "bf_m": 0.193,
    "tw_m": 0.0114,
    "tf_m": 0.019,
    "h_m": 0.428,
    "d_prime_m": 0.404,
    "area_m2": 0.012340000000000002,
    "ix_m4": 0.00044658,
    "wx_m3": 0.0019167,
    "rx_m": 0.19030000000000002,
    "zx_m3": 0.0021874,
    "iy_m4": 2.283e-05,
    "wy_m3": 0.00023659999999999998,
    "ry_m": 0.043,
    "zy_m3": 0.0003688,
    "j_m4": 1.1505e-06,
    "cw_m6": 1.13718e-06
  },
  {
    "profile_key": "GERDAU_W460X106.0",
    "designation": "W 460 x 106,0",
    "label": "W 460 x 106,0",
    "available_by_order": True,
    "mass_kg_m": 106.0,
    "d_m": 0.46900000000000003,
    "bf_m": 0.194,
    "tw_m": 0.0126,
    "tf_m": 0.0206,
    "h_m": 0.428,
    "d_prime_m": 0.404,
    "area_m2": 0.01351,
    "ix_m4": 0.00048978,
    "wx_m3": 0.0020886,
    "rx_m": 0.19039999999999999,
    "zx_m3": 0.0023945999999999998,
    "iy_m4": 2.515e-05,
    "wy_m3": 0.0002593,
    "ry_m": 0.0432,
    "zy_m3": 0.0004057,
    "j_m4": 1.4819e-06,
    "cw_m6": 1.260063e-06
  },
  {
    "profile_key": "GERDAU_W530X66.0",
    "designation": "W 530 x 66,0",
    "label": "W 530 x 66,0",
    "available_by_order": False,
    "mass_kg_m": 66.0,
    "d_m": 0.525,
    "bf_m": 0.165,
    "tw_m": 0.0089,
    "tf_m": 0.0114,
    "h_m": 0.502,
    "d_prime_m": 0.47800000000000004,
    "area_m2": 0.00836,
    "ix_m4": 0.00034971,
    "wx_m3": 0.0013322,
    "rx_m": 0.2046,
    "zx_m3": 0.001558,
    "iy_m4": 8.570000000000001e-06,
    "wy_m3": 0.0001039,
    "ry_m": 0.032,
    "zy_m3": 0.000166,
    "j_m4": 3.152e-07,
    "cw_m6": 5.628539999999999e-07
  },
  {
    "profile_key": "GERDAU_W530X72.0",
    "designation": "W 530 x 72,0",
    "label": "W 530 x 72,0",
    "available_by_order": False,
    "mass_kg_m": 72.0,
    "d_m": 0.524,
    "bf_m": 0.20700000000000002,
    "tw_m": 0.009000000000000001,
    "tf_m": 0.0109,
    "h_m": 0.502,
    "d_prime_m": 0.47800000000000004,
    "area_m2": 0.00916,
    "ix_m4": 0.00039969,
    "wx_m3": 0.0015255,
    "rx_m": 0.2089,
    "zx_m3": 0.0017559,
    "iy_m4": 1.615e-05,
    "wy_m3": 0.000156,
    "ry_m": 0.042,
    "zy_m3": 0.0002446,
    "j_m4": 3.3409999999999995e-07,
    "cw_m6": 1.060548e-06
  },
  {
    "profile_key": "GERDAU_W530X74.0",
    "designation": "W 530 x 74,0",
    "label": "W 530 x 74,0",
    "available_by_order": True,
    "mass_kg_m": 74.0,
    "d_m": 0.529,
    "bf_m": 0.166,
    "tw_m": 0.0097,
    "tf_m": 0.0136,
    "h_m": 0.502,
    "d_prime_m": 0.47800000000000004,
    "area_m2": 0.00951,
    "ix_m4": 0.00040969,
    "wx_m3": 0.0015489,
    "rx_m": 0.2076,
    "zx_m3": 0.0018049,
    "iy_m4": 1.041e-05,
    "wy_m3": 0.0001255,
    "ry_m": 0.033100000000000004,
    "zy_m3": 0.00020009999999999998,
    "j_m4": 4.7390000000000003e-07,
    "cw_m6": 6.88558e-07
  },
  {
    "profile_key": "GERDAU_W530X82.0",
    "designation": "W 530 x 82,0",
    "label": "W 530 x 82,0",
    "available_by_order": False,
    "mass_kg_m": 82.0,
    "d_m": 0.528,
    "bf_m": 0.209,
    "tw_m": 0.0095,
    "tf_m": 0.013300000000000001,
    "h_m": 0.501,
    "d_prime_m": 0.47700000000000004,
    "area_m2": 0.010450000000000001,
    "ix_m4": 0.00047569,
    "wx_m3": 0.0018017999999999999,
    "rx_m": 0.2134,
    "zx_m3": 0.0020585,
    "iy_m4": 2.028e-05,
    "wy_m3": 0.00019409999999999997,
    "ry_m": 0.0441,
    "zy_m3": 0.0003027,
    "j_m4": 5.123e-07,
    "cw_m6": 1.340255e-06
  },
  {
    "profile_key": "GERDAU_W530X85.0",
    "designation": "W 530 x 85,0",
    "label": "W 530 x 85,0",
    "available_by_order": False,
    "mass_kg_m": 85.0,
    "d_m": 0.535,
    "bf_m": 0.166,
    "tw_m": 0.0103,
    "tf_m": 0.0165,
    "h_m": 0.502,
    "d_prime_m": 0.47800000000000004,
    "area_m2": 0.01077,
    "ix_m4": 0.00048453,
    "wx_m3": 0.0018112999999999998,
    "rx_m": 0.2121,
    "zx_m3": 0.0020998,
    "iy_m4": 1.2630000000000001e-05,
    "wy_m3": 0.00015219999999999999,
    "ry_m": 0.0342,
    "zy_m3": 0.0002416,
    "j_m4": 7.293e-07,
    "cw_m6": 8.45463e-07
  },
  {
    "profile_key": "GERDAU_W530X92.0",
    "designation": "W 530 x 92,0",
    "label": "W 530 x 92,0",
    "available_by_order": False,
    "mass_kg_m": 92.0,
    "d_m": 0.533,
    "bf_m": 0.209,
    "tw_m": 0.010199999999999999,
    "tf_m": 0.0156,
    "h_m": 0.502,
    "d_prime_m": 0.47800000000000004,
    "area_m2": 0.01176,
    "ix_m4": 0.00055157,
    "wx_m3": 0.0020697,
    "rx_m": 0.2165,
    "zx_m3": 0.0023598,
    "iy_m4": 2.379e-05,
    "wy_m3": 0.00022759999999999998,
    "ry_m": 0.045,
    "zy_m3": 0.00035469999999999995,
    "j_m4": 7.55e-07,
    "cw_m6": 1.588565e-06
  },
  {
    "profile_key": "GERDAU_W530X101.0",
    "designation": "W 530 x 101,0",
    "label": "W 530 x 101,0",
    "available_by_order": True,
    "mass_kg_m": 101.0,
    "d_m": 0.537,
    "bf_m": 0.21,
    "tw_m": 0.0109,
    "tf_m": 0.0174,
    "h_m": 0.502,
    "d_prime_m": 0.47000000000000003,
    "area_m2": 0.013000000000000001,
    "ix_m4": 0.0006219800000000001,
    "wx_m3": 0.0023165,
    "rx_m": 0.2187,
    "zx_m3": 0.0026403999999999998,
    "iy_m4": 2.693e-05,
    "wy_m3": 0.0002565,
    "ry_m": 0.0455,
    "zy_m3": 0.0004006,
    "j_m4": 1.0604e-06,
    "cw_m6": 1.812734e-06
  },
  {
    "profile_key": "GERDAU_W530X109.0",
    "designation": "W 530 x 109,0",
    "label": "W 530 x 109,0",
    "available_by_order": True,
    "mass_kg_m": 109.0,
    "d_m": 0.539,
    "bf_m": 0.211,
    "tw_m": 0.0116,
    "tf_m": 0.0188,
    "h_m": 0.501,
    "d_prime_m": 0.46900000000000003,
    "area_m2": 0.01397,
    "ix_m4": 0.00067226,
    "wx_m3": 0.0024944999999999998,
    "rx_m": 0.2194,
    "zx_m3": 0.0028469999999999997,
    "iy_m4": 2.9520000000000002e-05,
    "wy_m3": 0.0002798,
    "ry_m": 0.046,
    "zy_m3": 0.00043739999999999995,
    "j_m4": 1.3138e-06,
    "cw_m6": 1.991291e-06
  },
  {
    "profile_key": "GERDAU_W530X123.0",
    "designation": "W 530 x 123,0",
    "label": "W 530 x 123,0",
    "available_by_order": True,
    "mass_kg_m": 123.0,
    "d_m": 0.544,
    "bf_m": 0.212,
    "tw_m": 0.0131,
    "tf_m": 0.0212,
    "h_m": 0.502,
    "d_prime_m": 0.47000000000000003,
    "area_m2": 0.015780000000000002,
    "ix_m4": 0.00076577,
    "wx_m3": 0.0028153,
    "rx_m": 0.22030000000000002,
    "zx_m3": 0.0032281,
    "iy_m4": 3.378e-05,
    "wy_m3": 0.0003187,
    "ry_m": 0.0463,
    "zy_m3": 0.0005002,
    "j_m4": 1.8669e-06,
    "cw_m6": 2.3004e-06
  },
  {
    "profile_key": "GERDAU_W530X138.0",
    "designation": "W 530 x 138,0",
    "label": "W 530 x 138,0",
    "available_by_order": True,
    "mass_kg_m": 138.0,
    "d_m": 0.549,
    "bf_m": 0.214,
    "tw_m": 0.0147,
    "tf_m": 0.0238,
    "h_m": 0.501,
    "d_prime_m": 0.46900000000000003,
    "area_m2": 0.01778,
    "ix_m4": 0.00087079,
    "wx_m3": 0.0031723,
    "rx_m": 0.2213,
    "zx_m3": 0.0036533,
    "iy_m4": 3.904e-05,
    "wy_m3": 0.0003648,
    "ry_m": 0.046900000000000004,
    "zy_m3": 0.0005744999999999999,
    "j_m4": 2.6276e-06,
    "cw_m6": 2.680751e-06
  },
  {
    "profile_key": "GERDAU_W610X82.0",
    "designation": "W 610 x 82,0",
    "label": "W 610 x 82,0",
    "available_by_order": False,
    "mass_kg_m": 82.0,
    "d_m": 0.599,
    "bf_m": 0.178,
    "tw_m": 0.01,
    "tf_m": 0.0128,
    "h_m": 0.5730000000000001,
    "d_prime_m": 0.541,
    "area_m2": 0.01051,
    "ix_m4": 0.0005662800000000001,
    "wx_m3": 0.0018907999999999998,
    "rx_m": 0.2321,
    "zx_m3": 0.0022199,
    "iy_m4": 1.2100000000000001e-05,
    "wy_m3": 0.0001359,
    "ry_m": 0.0339,
    "zy_m3": 0.00021899999999999998,
    "j_m4": 5.182e-07,
    "cw_m6": 1.033595e-06
  },
  {
    "profile_key": "GERDAU_W610X92.0",
    "designation": "W 610 x 92,0",
    "label": "W 610 x 92,0",
    "available_by_order": False,
    "mass_kg_m": 92.0,
    "d_m": 0.603,
    "bf_m": 0.179,
    "tw_m": 0.0109,
    "tf_m": 0.015,
    "h_m": 0.5730000000000001,
    "d_prime_m": 0.541,
    "area_m2": 0.011840000000000002,
    "ix_m4": 0.00065277,
    "wx_m3": 0.0021650999999999997,
    "rx_m": 0.2348,
    "zx_m3": 0.0025358,
    "iy_m4": 1.4420000000000001e-05,
    "wy_m3": 0.00016109999999999999,
    "ry_m": 0.0349,
    "zy_m3": 0.0002593,
    "j_m4": 7.473e-07,
    "cw_m6": 1.239349e-06
  },
  {
    "profile_key": "GERDAU_W610X101.0",
    "designation": "W 610 x 101,0",
    "label": "W 610 x 101,0",
    "available_by_order": False,
    "mass_kg_m": 101.0,
    "d_m": 0.603,
    "bf_m": 0.228,
    "tw_m": 0.0105,
    "tf_m": 0.0149,
    "h_m": 0.5730000000000001,
    "d_prime_m": 0.541,
    "area_m2": 0.013030000000000002,
    "ix_m4": 0.00077003,
    "wx_m3": 0.002554,
    "rx_m": 0.24309999999999998,
    "zx_m3": 0.0029227,
    "iy_m4": 2.951e-05,
    "wy_m3": 0.0002588,
    "ry_m": 0.047599999999999996,
    "zy_m3": 0.000405,
    "j_m4": 8.168000000000001e-07,
    "cw_m6": 2.544966e-06
  },
  {
    "profile_key": "GERDAU_W610X113.0",
    "designation": "W 610 x 113,0",
    "label": "W 610 x 113,0",
    "available_by_order": False,
    "mass_kg_m": 113.0,
    "d_m": 0.608,
    "bf_m": 0.228,
    "tw_m": 0.0112,
    "tf_m": 0.0173,
    "h_m": 0.5730000000000001,
    "d_prime_m": 0.541,
    "area_m2": 0.014530000000000001,
    "ix_m4": 0.00088196,
    "wx_m3": 0.0029011999999999996,
    "rx_m": 0.2464,
    "zx_m3": 0.0033129,
    "iy_m4": 3.426e-05,
    "wy_m3": 0.0003005,
    "ry_m": 0.048600000000000004,
    "zy_m3": 0.0004697,
    "j_m4": 1.165e-06,
    "cw_m6": 2.981078e-06
  },
  {
    "profile_key": "GERDAU_W610X125.0",
    "designation": "W 610 x 125,0",
    "label": "W 610 x 125,0",
    "available_by_order": False,
    "mass_kg_m": 125.0,
    "d_m": 0.612,
    "bf_m": 0.229,
    "tw_m": 0.0119,
    "tf_m": 0.019600000000000003,
    "h_m": 0.5730000000000001,
    "d_prime_m": 0.541,
    "area_m2": 0.01601,
    "ix_m4": 0.0009918400000000001,
    "wx_m3": 0.0032413,
    "rx_m": 0.2489,
    "zx_m3": 0.0036973,
    "iy_m4": 3.933e-05,
    "wy_m3": 0.0003435,
    "ry_m": 0.0496,
    "zy_m3": 0.0005363,
    "j_m4": 1.595e-06,
    "cw_m6": 3.441766e-06
  },
  {
    "profile_key": "GERDAU_W610X140.0",
    "designation": "W 610 x 140,0",
    "label": "W 610 x 140,0",
    "available_by_order": False,
    "mass_kg_m": 140.0,
    "d_m": 0.617,
    "bf_m": 0.23,
    "tw_m": 0.0131,
    "tf_m": 0.0222,
    "h_m": 0.5730000000000001,
    "d_prime_m": 0.541,
    "area_m2": 0.01793,
    "ix_m4": 0.00112619,
    "wx_m3": 0.0036504999999999997,
    "rx_m": 0.2506,
    "zx_m3": 0.0041731,
    "iy_m4": 4.515e-05,
    "wy_m3": 0.0003926,
    "ry_m": 0.050199999999999995,
    "zy_m3": 0.000614,
    "j_m4": 2.2501e-06,
    "cw_m6": 3.981687e-06
  },
  {
    "profile_key": "GERDAU_W610X155.0",
    "designation": "W 610 x 155,0",
    "label": "W 610 x 155,0",
    "available_by_order": False,
    "mass_kg_m": 155.0,
    "d_m": 0.611,
    "bf_m": 0.324,
    "tw_m": 0.0127,
    "tf_m": 0.019,
    "h_m": 0.5730000000000001,
    "d_prime_m": 0.541,
    "area_m2": 0.01981,
    "ix_m4": 0.00129583,
    "wx_m3": 0.004241699999999999,
    "rx_m": 0.25579999999999997,
    "zx_m3": 0.0047491,
    "iy_m4": 0.00010783,
    "wy_m3": 0.0006656,
    "ry_m": 0.0738,
    "zy_m3": 0.0010226,
    "j_m4": 2.0077000000000003e-06,
    "cw_m6": 9.436714e-06
  },
  {
    "profile_key": "GERDAU_W610X174.0",
    "designation": "W 610 x 174,0",
    "label": "W 610 x 174,0",
    "available_by_order": False,
    "mass_kg_m": 174.0,
    "d_m": 0.616,
    "bf_m": 0.325,
    "tw_m": 0.014,
    "tf_m": 0.0216,
    "h_m": 0.5730000000000001,
    "d_prime_m": 0.541,
    "area_m2": 0.02228,
    "ix_m4": 0.00147754,
    "wx_m3": 0.0047972,
    "rx_m": 0.2575,
    "zx_m3": 0.0053833,
    "iy_m4": 0.00012374,
    "wy_m3": 0.0007614999999999999,
    "ry_m": 0.0745,
    "zy_m3": 0.0011710999999999998,
    "j_m4": 2.8688e-06,
    "cw_m6": 1.0915665e-05
  },
  {
    "profile_key": "GERDAU_W610X195.0",
    "designation": "W 610 x 195,0",
    "label": "W 610 x 195,0",
    "available_by_order": True,
    "mass_kg_m": 195.0,
    "d_m": 0.622,
    "bf_m": 0.327,
    "tw_m": 0.0154,
    "tf_m": 0.024399999999999998,
    "h_m": 0.5730000000000001,
    "d_prime_m": 0.541,
    "area_m2": 0.02501,
    "ix_m4": 0.00168484,
    "wx_m3": 0.0054175,
    "rx_m": 0.2596,
    "zx_m3": 0.006095399999999999,
    "iy_m4": 0.0001424,
    "wy_m3": 0.0008709,
    "ry_m": 0.0755,
    "zy_m3": 0.001341,
    "j_m4": 4.052900000000001e-06,
    "cw_m6": 1.2695301999999999e-05
  },
  {
    "profile_key": "GERDAU_W610X217.0",
    "designation": "W 610 x 217,0",
    "label": "W 610 x 217,0",
    "available_by_order": True,
    "mass_kg_m": 217.0,
    "d_m": 0.628,
    "bf_m": 0.328,
    "tw_m": 0.0165,
    "tf_m": 0.0277,
    "h_m": 0.5730000000000001,
    "d_prime_m": 0.541,
    "area_m2": 0.02784,
    "ix_m4": 0.00191395,
    "wx_m3": 0.006095399999999999,
    "rx_m": 0.2622,
    "zx_m3": 0.0068687999999999996,
    "iy_m4": 0.00016316,
    "wy_m3": 0.0009949,
    "ry_m": 0.0766,
    "zy_m3": 0.0015316,
    "j_m4": 5.702100000000001e-06,
    "cw_m6": 1.4676643e-05
  }
]


def _seed_section_profiles_once(db: Session) -> None:
    for row in GERDAU_W_SERIES_I_PROFILES:
        values = {**GERDAU_W_SERIES_I_SOURCE, **row}
        profile = db.execute(
            select(SectionProfile).where(SectionProfile.profile_key == values["profile_key"])
        ).scalar_one_or_none()
        if profile is None:
            db.add(SectionProfile(**values))
            continue
        for key, value in values.items():
            setattr(profile, key, value)


def seed_section_profiles(db: Session) -> None:
    for attempt in range(3):
        try:
            _seed_section_profiles_once(db)
            db.commit()
            return
        except IntegrityError:
            db.rollback()
            if attempt == 2:
                raise


def _catalog_value_matches(actual: object, expected: object) -> bool:
    if isinstance(expected, float):
        if isinstance(actual, bool) or not isinstance(actual, (int, float)):
            return False
        actual_float = float(actual)
        return (
            math.isfinite(actual_float)
            and math.isfinite(expected)
            and math.isclose(
                actual_float,
                expected,
                rel_tol=CATALOG_STORAGE_REL_TOLERANCE,
                abs_tol=0.0,
            )
        )
    return actual == expected


def assert_section_profiles_seeded(db: Session) -> None:
    """Fail if the managed catalog would require any insert, update or removal.

    Production startup and deploy use this read-only gate. Catalog changes must be
    applied by an explicit migration/operation instead of an implicit application
    startup commit.
    """

    expected_rows = {
        row["profile_key"]: {**GERDAU_W_SERIES_I_SOURCE, **row}
        for row in GERDAU_W_SERIES_I_PROFILES
    }
    profiles = db.execute(
        select(SectionProfile).where(
            SectionProfile.source_id == GERDAU_W_SERIES_I_SOURCE["source_id"]
        )
    ).scalars().all()
    actual_rows = {profile.profile_key: profile for profile in profiles}
    missing = sorted(set(expected_rows) - set(actual_rows))
    unexpected = sorted(set(actual_rows) - set(expected_rows))
    changed: list[str] = []
    for profile_key in sorted(set(expected_rows) & set(actual_rows)):
        profile = actual_rows[profile_key]
        expected = expected_rows[profile_key]
        if any(
            not _catalog_value_matches(getattr(profile, field), value)
            for field, value in expected.items()
        ):
            changed.append(profile_key)
    if missing or unexpected or changed:
        details: list[str] = []
        if missing:
            details.append("ausentes=" + ",".join(missing[:5]))
        if unexpected:
            details.append("inesperados=" + ",".join(unexpected[:5]))
        if changed:
            details.append("divergentes=" + ",".join(changed[:5]))
        raise RuntimeError(
            "Catalogo de perfis exige operacao explicita antes da release: "
            + "; ".join(details)
        )
