# frozen_string_literal: true
module Stupidedi
  module TransactionSets
    module TwoThousandOne
      module Implementations
        b = Builder
        d = Schema
        r = SegmentReqs
        e = ElementReqs
        s = SegmentDefs

        SH856 = b.build("SH", "856", "Ship Notice/Manifest",
          d::TableDef.header("Heading",
            b::Segment(10, s:: ST, "Transaction Set Header", r::Required, d::RepeatCount.bounded(1),
              b::Element(e::Required,    "Transaction Set Identifier Code", b::Values("856")),
              b::Element(e::Required,    "Transaction Set Control Number")),
            b::Segment(20, s::BSN, "Beginning Segment for Ship Notice", r::Required, d::RepeatCount.bounded(1),
              b::Element(e::Required,    "Transaction Set Purpose Code", b::Values("00")),
              b::Element(e::Required,    "Shipment Identification"),
              b::Element(e::Required,    "Category - Ship Notice Date"),
              b::Element(e::Situational, "Subcategory - Ship Notice Time"),
              b::Element(e::NotUsed,     "Hierarchical Structure Code"),
              b::Element(e::NotUsed,     "Transaction Type Code"),
              b::Element(e::NotUsed,     "Status Reason Code")),
            b::Segment(40, s::DTM, "Date/Time/Period", r::Situational, d::RepeatCount.bounded(10),
              b::Element(e::Required,    "Date/Time Qualifier", b::Values("011")),
              b::Element(e::Situational, "Date - Ship Date"),
              b::Element(e::Situational, "Time - Ship Time"),
              b::Element(e::NotUsed,     "Time Code"),
              b::Element(e::NotUsed,     "Century"),
              b::Element(e::NotUsed,     "Date Time Period Format Qualifier"),
              b::Element(e::NotUsed,     "Date Time Period"))),

          d::TableDef.detail("Detail",
            d::LoopDef.build("HL", d::RepeatCount.bounded(1),
              b::Segment(50, s:: HL, "Hierarchical Level - Shipment Level", r::Required, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Hierarchical ID Number", b::Values("1")),
                b::Element(e::NotUsed,     "Hierarchical Parent ID Number"),
                b::Element(e::Required,    "Hierarchical Level Code", b::Values("S")),
                b::Element(e::NotUsed,     "Hierarchical Child Code")),
              b::Segment(130, s::MEA, "Measurements", r::Situational, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Measurement Reference ID Code", b::Values("PD")),
                b::Element(e::Required,    "Measurement Qualifier", b::Values("G")),
                b::Element(e::Situational, "Measurement Value - Gross Weight"),
                b::Element(e::Required,    "Unit or Basis for Measurement Code", b::Values("LB")),
                b::Element(e::Situational, "Range Minimum", b::Values("0")),
                b::Element(e::Situational, "Range Maximum", b::Values("0"))),
              b::Segment(160, s::TD1, "Carrier Details (Quantity and Weight)", r::Situational, d::RepeatCount.bounded(1),
                b::Element(e::Situational, "Packaging Code"),
                b::Element(e::Situational, "Lading Quantity"),
                b::Element(e::NotUsed,     "Commodity Code Qualifier"),
                b::Element(e::NotUsed,     "Commodity Code"),
                b::Element(e::NotUsed,     "Lading Description"),
                b::Element(e::NotUsed,     "Weight Qualifier"),
                b::Element(e::NotUsed,     "Weight"),
                b::Element(e::NotUsed,     "Unit or Basis for Measurement Code"),
                b::Element(e::NotUsed,     "Volume"),
                b::Element(e::NotUsed,     "Unit or Basis for Measurement Code")),
              b::Segment(180, s::TD3, "Carrier Details (Equipment)", r::Situational, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Equipment Description Code"),
                b::Element(e::Situational, "Equipment Initial - SCAC code"),
                b::Element(e::Situational, "Equipment Number - Trailer Number")),
             b::Segment( 200, s::REF, "Reference Numbers", r::Situational, d::RepeatCount.bounded(200),
                b::Element(e::Required,    "Reference Number Qualifier", b::Values("BM","PK")),
                b::Element(e::Situational, "Reference Number - Bill Of Lading Number"),
                b::Element(e::NotUsed,     "Description"),
                b::Element(e::NotUsed,     "Reference Identifier")),

              # b::Segment(200, s::REF, "Reference Numbers",
              #   r::Situational, d::RepeatCount.bounded(2),
              #   b::Element(e::Required,    "Reference Number Qualifier", b::Values("BM","PK")),
              #   b::Element(e::Situational, "Reference Number - Bill Of Lading Number"),
              #   b::Element(e::Situational, "Description"),
              #   b::Element(e::Situational, "Reference Identifier"))

              d::LoopDef.build("N1", d::RepeatCount.bounded(200),
                b::Segment(270, s:: N1, "Name -Supplier", r::Situational, d::RepeatCount.bounded(1),
                  b::Element(e::Required,    "Entity Identifier Code", b::Values("SU")),
                  b::Element(e::Situational, "Name - Supplier Name"),
                  b::Element(e::Situational, "Identification Code Qualifier", b::Values("92")),
                  b::Element(e::Situational, "Identification Code - Supplier Code")))),

            d::LoopDef.build("HL", d::RepeatCount.bounded(199999),
              b::Segment( 50, s:: HL, "Hierarchical Level - Tare Level", r::Situational, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Hierarchical ID Number"),
                b::Element(e::Situational, "Hierarchical Parent ID Number"),
                b::Element(e::Required,    "Hierarchical Level Code", b::Values("T")),
                b::Element(e::Situational, "Hierarchical Child Code", b::Values("0","1"))),
              b::Segment( 200, s::REF, "Reference Numbers", r::Situational, d::RepeatCount.bounded(200),
                b::Element(e::Required,    "Reference Number Qualifier", b::Values("LS")),
                b::Element(e::Situational, "Reference Number - Mixed or Master Label Serial Number", b::Values("4S","5S","M","G","S")),
                b::Element(e::NotUsed,     "Description"),
                b::Element(e::NotUsed,     "Reference Identifier"))),

            d::LoopDef.build("HL", d::RepeatCount.bounded(199999),
              b::Segment( 50, s:: HL, "Hierarchical Level - Item Level", r::Situational, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Hierarchical ID Number"),
                b::Element(e::Situational, "Hierarchical Parent ID Number"),
                b::Element(e::Required,    "Hierarchical Level Code", b::Values("I")),
                b::Element(e::Situational, "Hierarchical Child Code", b::Values("0","1"))),
              b::Segment( 60, s::LIN, "Item Identification", r::Situational, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Product/Service ID Qualifier", b::Values("BP")),
                b::Element(e::Situational, "Product/Service ID - Nissan Part Number"),
                b::Element(e::Situational, "Product/Service ID Qualifier", b::Values("ON")),
                b::Element(e::Situational, "Product/Service ID - Receipt Authorization Number (RAN)"),
                b::Element(e::Situational, "Product/Service ID Qualifier", b::Values("SN")),
                b::Element(e::Situational, "Product/Service ID - Coil Number"),
                b::Element(e::NotUsed,     "Product/Service ID Qualifier"),
                b::Element(e::NotUsed,     "Product/Service ID"),
                b::Element(e::NotUsed,     "Product/Service ID Qualifier"),
                b::Element(e::NotUsed,     "Product/Service ID"),
                b::Element(e::NotUsed,     "Product/Service ID Qualifier"),
                b::Element(e::NotUsed,     "Product/Service ID"),
                b::Element(e::NotUsed,     "Product/Service ID Qualifier"),
                b::Element(e::NotUsed,     "Product/Service ID"),
                b::Element(e::NotUsed,     "Product/Service ID Qualifier"),
                b::Element(e::NotUsed,     "Product/Service ID"),
                b::Element(e::NotUsed,     "Product/Service ID Qualifier"),
                b::Element(e::NotUsed,     "Product/Service ID"),
                b::Element(e::NotUsed,     "Product/Service ID Qualifier"),
                b::Element(e::NotUsed,     "Product/Service ID"),
                b::Element(e::NotUsed,     "Product/Service ID Qualifier"),
                b::Element(e::NotUsed,     "Product/Service ID"),
                b::Element(e::NotUsed,     "Product/Service ID Qualifier"),
                b::Element(e::NotUsed,     "Product/Service ID"),
                b::Element(e::NotUsed,     "Product/Service ID Qualifier"),
                b::Element(e::NotUsed,     "Product/Service ID"),
                b::Element(e::NotUsed,     "Product/Service ID Qualifier"),
                b::Element(e::NotUsed,     "Product/Service ID"),
                b::Element(e::NotUsed,     "Product/Service ID Qualifier"),
                b::Element(e::NotUsed,     "Product/Service ID"),
                b::Element(e::NotUsed,     "Product/Service ID Qualifier")),
              b::Segment( 80, s::SN1, "Item Detail (Shipment)", r::Situational, d::RepeatCount.bounded(1),
                b::Element(e::NotUsed,     "Assigned Identification"),
                b::Element(e::Required,    "Number of Units Shipped"),
                b::Element(e::Situational, "Unit or Basis for Measurement Code"),
                b::Element(e::NotUsed,     "Quantity Shipped to Date"),
                b::Element(e::NotUsed,     "Quantity Ordered"),
                b::Element(e::NotUsed,     "Unit or Basis for Measurement Code"),
                b::Element(e::NotUsed,     "Returnable Container Load Make-Up Code"),
                b::Element(e::NotUsed,     "Line Item Status Code")),
              b::Segment(110, s::PO4, "Item Physical Details", r::Situational, d::RepeatCount.unbounded,
                b::Element(e::Situational, "Pack"),
                b::Element(e::Situational, "Size"),
                b::Element(e::Situational, "Unit or Basis for Measurement Code")),
              b::Segment(200, s::REF, "Reference Identification", r::Situational, d::RepeatCount.bounded(12),
                b::Element(e::Required,    "Reference Identification Qualifier", b::Values("LS")),
                b::Element(e::Situational, "Reference Number - Label Serial Number"),
                b::Element(e::NotUsed,     "Description"),
                b::Element(e::NotUsed,     "Reference Identifier"))),

            d::LoopDef.build("HL", d::RepeatCount.bounded(199999),
              b::Segment( 50, s:: HL, "Hierarchical Level -Pack Level", r::Situational, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Hierarchical ID Number"),
                b::Element(e::Situational, "Hierarchical Parent ID Number"),
                b::Element(e::Required,    "Hierarchical Level Code", b::Values("P")),
                b::Element(e::Situational, "Hierarchical Child Code", b::Values("0"))),
              b::Segment( 80, s::SN1, "Item Detail (Shipment)", r::Situational, d::RepeatCount.bounded(1),
                b::Element(e::NotUsed,     "Assigned Identification"),
                b::Element(e::Required,    "Number of Units Shipped"),
                b::Element(e::Required,    "Unit or Basis for Measurement Code"),
                b::Element(e::NotUsed,     "Quantity Shipped to Date"),
                b::Element(e::NotUsed,     "Quantity Ordered"),
                b::Element(e::NotUsed,     "Unit or Basis for Measurement Code"),
                b::Element(e::NotUsed,     "Returnable Container Load Make-Up Code"),
                b::Element(e::NotUsed,     "Line Item Status Code")),
              b::Segment(200, s::REF, "Reference Numbers", r::Situational, d::RepeatCount.bounded(200),
                b::Element(e::Required,    "Reference Number Qualifier", b::Values("LS")),
                b::Element(e::Situational, "Reference Number - Label Serial Number."),
                b::Element(e::NotUsed,     "Description"),
                b::Element(e::NotUsed,     "Reference Identifier")))),

          d::TableDef.header("Summary",
            d::LoopDef.build("CTT", d::RepeatCount.bounded(1),
              b::Segment(380, s::CTT, "Transaction Totals", r::Required, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Number of Line Items"),
                b::Element(e::Situational, "Hash Total"),
                b::Element(e::NotUsed,     "Weight"),
                b::Element(e::NotUsed,     "Unit or Basis for Measurement Code"),
                b::Element(e::NotUsed,     "Volume"),
                b::Element(e::NotUsed,     "Unit or Basis for Measurement Code"),
                b::Element(e::NotUsed,     "Description")),
              b::Segment(390, s:: SE, "Transaction Set Trailer", r::Required, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Number of Included Segments"),
                b::Element(e::Required,    "Transaction Set Control Number")))))

      end
    end
  end
end
