digraph logic {
  graph [rankdir=TB, fontname="Helvetica", fontsize=13,
         label=<<B>Logic Diagram — demo_customs_clvs  [clvs_eligibility]</B>>, labelloc=t,
         pad=0.4, nodesep=0.90, ranksep=1.10, bgcolor="white",
         splines=spline]
  node  [fontname="Helvetica", fontsize=11, shape=plaintext]
  edge  [fontname="Helvetica", fontsize=10]

  // ── trigger ─────────────────────────────────────────────────────
  TRIGGER [label=<<TABLE BORDER="2" CELLBORDER="0" CELLPADDING="5" BGCOLOR="#e8f5e9" COLOR="#27ae60"><TR><TD><FONT COLOR="#27ae60"><B>&#9889; ShipmentCommodity inserted</B></FONT></TD></TR></TABLE>>, shape=plaintext]

  // ── schema layer ──────────────────────────────────────────────────
  Shipment [label=<<TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0" COLOR="#4a6fa5"><TR><TD COLSPAN="3" BGCOLOR="#4a6fa5"><FONT COLOR="white"><B> Shipment </B></FONT></TD></TR><TR><TD PORT="Shipment_prohibited_commodity_count_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="Shipment_prohibited_commodity_count" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> prohibited_commodity_count </FONT></TD><TD PORT="Shipment_prohibited_commodity_count_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="Shipment_controlled_item_count_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="Shipment_controlled_item_count" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> controlled_item_count </FONT></TD><TD PORT="Shipment_controlled_item_count_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="Shipment_clvs_eligible_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="Shipment_clvs_eligible" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> clvs_eligible </FONT> <FONT COLOR="#e67e22" POINT-SIZE="9">= 1 if clvs_reason == "" else 0</FONT></TD><TD PORT="Shipment_clvs_eligible_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="Shipment_clvs_reason_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="Shipment_clvs_reason" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> clvs_reason </FONT> <FONT COLOR="#e67e22" POINT-SIZE="9">= _clvs_reason(row)</FONT></TD><TD PORT="Shipment_clvs_reason_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="Shipment_authorized_clvs_courier_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="Shipment_authorized_clvs_courier" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> authorized_clvs_courier </FONT></TD><TD PORT="Shipment_authorized_clvs_courier_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="Shipment_local_customs_value_amt_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="Shipment_local_customs_value_amt" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> local_customs_value_amt </FONT></TD><TD PORT="Shipment_local_customs_value_amt_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="Shipment_clvs_lvs_threshold_cad_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="Shipment_clvs_lvs_threshold_cad" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> clvs_lvs_threshold_cad </FONT></TD><TD PORT="Shipment_clvs_lvs_threshold_cad_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="Shipment_customs_office_id_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="Shipment_customs_office_id" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> customs_office_id </FONT></TD><TD PORT="Shipment_customs_office_id_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="Shipment_session_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="Shipment_session" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> session </FONT></TD><TD PORT="Shipment_session_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR></TABLE>>]
  ShipmentCommodity [label=<<TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0" COLOR="#4a6fa5"><TR><TD COLSPAN="3" BGCOLOR="#4a6fa5"><FONT COLOR="white"><B> ShipmentCommodity </B></FONT></TD></TR><TR><TD PORT="ShipmentCommodity_is_prohibited_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="ShipmentCommodity_is_prohibited" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> is_prohibited </FONT> <FONT COLOR="#e67e22" POINT-SIZE="9">= _is_prohibited(row)</FONT></TD><TD PORT="ShipmentCommodity_is_prohibited_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="ShipmentCommodity_controlled_regulated_goods_id_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="ShipmentCommodity_controlled_regulated_goods_id" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> controlled_regulated_goods_id </FONT></TD><TD PORT="ShipmentCommodity_controlled_regulated_goods_id_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="ShipmentCommodity_hazardous_material_cd_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="ShipmentCommodity_hazardous_material_cd" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> hazardous_material_cd </FONT></TD><TD PORT="ShipmentCommodity_hazardous_material_cd_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR></TABLE>>]
  SysConfig [label=<<TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0" COLOR="#4a6fa5"><TR><TD COLSPAN="3" BGCOLOR="#4a6fa5"><FONT COLOR="white"><B> SysConfig </B></FONT></TD></TR><TR><TD PORT="SysConfig_clvs_lvs_threshold_cad_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="SysConfig_clvs_lvs_threshold_cad" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> clvs_lvs_threshold_cad </FONT></TD><TD PORT="SysConfig_clvs_lvs_threshold_cad_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR></TABLE>>]
  // ── rank groupings ────────────────────────────────────────────────
  { rank=min; SysConfig }
  { rank=same; Shipment }
  { rank=max; ShipmentCommodity; TRIGGER }

  // ── FK relationships ───────────────────────────────────────────
  Shipment -> SysConfig [color="#e0e0e0", style=solid, arrowhead=none, arrowtail=crow, dir=both, penwidth=0.7, constraint=false, weight=1]
  ShipmentCommodity -> Shipment [color="#e0e0e0", style=solid, arrowhead=none, arrowtail=crow, dir=both, penwidth=0.7, constraint=false, weight=1]

  // ── trigger edge ──────────────────────────────────────────────
  TRIGGER -> ShipmentCommodity [color="#27ae60", style=bold, arrowhead=vee, penwidth=2, weight=10]

  // ── logic edges ────────────────────────────────────────────────────
  SysConfig:SysConfig_clvs_lvs_threshold_cad_w -> Shipment:Shipment_clvs_lvs_threshold_cad_w [label="1", color="#444444", fontcolor="#444444", arrowhead=vee, penwidth=1.8, weight=8]
  // INTRA:Shipment:clvs_reason:clvs_eligible:2:0
  // INTRA:ShipmentCommodity:hazardous_material_cd:is_prohibited:3:0
  // INTRA:Shipment:prohibited_commodity_count:clvs_reason:4:1
  // INTRA:Shipment:session:clvs_reason:4:2
  ShipmentCommodity -> Shipment:Shipment_prohibited_commodity_count_w [label="5", color="#444444", fontcolor="#444444", arrowhead=vee, penwidth=2, style=dashed, weight=8, tailport=w]
  ShipmentCommodity -> Shipment:Shipment_controlled_item_count_w [label="6", color="#444444", fontcolor="#444444", arrowhead=vee, penwidth=2, style=dashed, weight=8, tailport=w]

  // ── events (right cluster) ─────────────────────────────────────
  subgraph cluster_events {
    style=invis
    evt__set_customs_office [label=<<TABLE BORDER="1" CELLBORDER="0" CELLPADDING="4" BGCOLOR="#e8f5e9" COLOR="#27ae60"><TR><TD><FONT COLOR="#27ae60" POINT-SIZE="10">&#9889; _set_customs_office</FONT></TD></TR></TABLE>>, shape=plaintext]
    evt__set_controlled_good [label=<<TABLE BORDER="1" CELLBORDER="0" CELLPADDING="4" BGCOLOR="#e8f5e9" COLOR="#27ae60"><TR><TD><FONT COLOR="#27ae60" POINT-SIZE="10">&#9889; _set_controlled_good</FONT></TD></TR></TABLE>>, shape=plaintext]
  }
  Shipment -> evt__set_customs_office [label="early", color="#27ae60", style=dashed, arrowhead=open, penwidth=1.2, fontcolor="#27ae60", constraint=false]
  ShipmentCommodity -> evt__set_controlled_good [label="early", color="#27ae60", style=dashed, arrowhead=open, penwidth=1.2, fontcolor="#27ae60", constraint=false]
}