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

        PS830 = b.build("PS", "830", "",
          d::TableDef.header("Header",
            b::Segment(10, s:: ST, "Transaction Set Header #1", r::Required, d::RepeatCount.bounded(1),
              b::Element(e::Required,    "Transaction Set Identifier Code", b::Values("830")),
              b::Element(e::Required,    "Transaction Set Control Number")),
            b::Segment(20, s::BFR, "Beginning Segment for Planning Schedule #1", r::Required, d::RepeatCount.bounded(1),
              b::Element(e::Required,    "Transaction Set Purpose Code", b::Values("00")),
              b::Element(e::Situational, "Reference Identification"),
              b::Element(e::Situational, "Release Number"),
              b::Element(e::Required,    "Schedule Type Qualifier", b::Values("SH")),
              b::Element(e::Required,    "Schedule Quantity Qualifier", b::Values("A")),
              b::Element(e::Required,    "Date"),
              b::Element(e::Situational, "Date"),
              b::Element(e::Required,    "Date"),
              b::Element(e::NotUsed,     ""),
              b::Element(e::Situational, "Purchase Order Number")),
            b::Segment(50, s::REF, "Reference Identification #1", r::Situational, d::RepeatCount.bounded(12),
              b::Element(e::Required,    "Reference Identification Qualifier", b::Values("ZZ")),
              b::Element(e::Situational, "Reference Identification"),
              b::Element(e::Situational, "Description")),

            d::LoopDef.build("N1 #1", d::RepeatCount.bounded(2),
              b::Segment(230, s:: N1, "Name - Header", r::Situational, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Entity Identifier Code", b::Values("BT", "EV")),
                b::Element(e::Situational, "Name"),
                b::Element(e::Situational, "Identification Code Qualifier", b::Values("01","ZZ")),
                b::Element(e::Situational, "Identification Code"),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     "")))),

          d::TableDef.header("Detail",
            d::LoopDef.build("LIN - Detail 1", d::RepeatCount.unbounded,
              b::Segment(10, s::LIN, "Warehouse Shipment Identification - Detail 1", r::Required, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Reporting Code", b::Values("F")),
                b::Element(e::Required,    "Depositor Order Number"),
                b::Element(e::Situational, "Date"),
                b::Element(e::Required,    "Shipment Identification Number"),
                b::Element(e::Situational, "Agent Shipment ID Number"),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     "")),
              b::Segment(20, s::UIT, "Unit Detail - Detail 1", r::Situational, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Composite Unit of Measure",
                b::Element(e::Required,    "Unit or Basis for Measurement Code", b::Values("PC")),
                b::Element(e::NotUsed,     "Exponent"),
                b::Element(e::NotUsed,     "Multiplier"),
                b::Element(e::Situational, "Unit or Basis for Measurement Code", b::Values("LB")),
                b::Element(e::NotUsed,     "Exponent"),
                b::Element(e::Situational, "Multiplier")),
                b::Element(e::Situational, "Unit Price")),
              b::Segment(80, s::PID, "Product/Item Description - Detail 1", r::Situational, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Item Description Type", b::Values("F")),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::Required,    "Description"),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     ""),
                b::Element(e::NotUsed,     "")),

              d::LoopDef.build("N1 #1", d::RepeatCount.bounded(1),
                b::Segment(320, s:: N1, "Name - Detail 1", r::Situational, d::RepeatCount.bounded(1),
                  b::Element(e::Required,    "Entity Identifier Code", b::Values("ST", "SF")),
                  b::Element(e::Situational, "Name"),
                  b::Element(e::Situational, "Identification Code Qualifier", b::Values("91")),
                  b::Element(e::Situational, "Identification Code"),
                  b::Element(e::NotUsed,     ""),
                  b::Element(e::NotUsed,     ""))),

              d::LoopDef.build("SDP #1", d::RepeatCount.bounded(1),
                b::Segment(450, s::SDP, "Ship/Delivery Pattern - Detail 1", r::Situational, d::RepeatCount.bounded(1),
                  b::Element(e::Required,    "Ship/Delivery or Calendar Pattern Code", b::Values("Y")),
                  b::Element(e::Required,    "Ship/Delivery Pattern Time Code", b::Values("Y"))),
                b::Segment(460, s::FST, "Forecast Schedule - Detail 1", r::Situational, d::RepeatCount.bounded(6),
                  b::Element(e::Required,    "Quantity"),
                  b::Element(e::Required,    "Forecast Qualifier", b::Values("C", "D")),
                  b::Element(e::Required,    "Forecast Timing Qualifier", b::Values("F")),
                  b::Element(e::Required,    "Date"),
                  b::Element(e::Situational, "Date"),
                  b::Element(e::NotUsed,     ""),
                  b::Element(e::NotUsed,     ""),
                  b::Element(e::Situational, "Reference Identification Qualifier"),
                  b::Element(e::Situational, "Reference Identification"))),

              d::LoopDef.build("SHP #1", d::RepeatCount.bounded(1),
                b::Segment(470, s::SHP, "Shipped/Received Information - Detail 1", r::Situational, d::RepeatCount.bounded(1),
                  b::Element(e::Situational, "Quantity Qualifier", b::Values("02")),
                  b::Element(e::Situational, "Quantity"),
                  b::Element(e::Situational, "Date/Time Qualifier", b::Values("011")),
                  b::Element(e::Situational, "Date"))))),

          d::TableDef.header("Summary",
            b::Segment(10, s::CTT, "Transaction Totals", r::Situational, d::RepeatCount.bounded(1),
              b::Element(e::Required,    "Number of Units Shipped"),
              b::Element(e::NotUsed,     ""),
              b::Element(e::NotUsed,     ""),
              b::Element(e::NotUsed,     ""),
              b::Element(e::NotUsed,     ""),
              b::Element(e::NotUsed,     ""),
              b::Element(e::NotUsed,     "")),
            b::Segment(30, 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
