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

        WA142 = b.build("WA", "142", "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("142")),
              b::Element(e::Required,    "Transaction Set Control Number")),
            b::Segment(20, s::BGN, "Beginning Segment", r::Required, d::RepeatCount.bounded(1),
              b::Element(e::Required,    "Transaction Set Purpose Code", b::Values("00","31","32")),
              b::Element(e::Required,    "Reference Number - Warranty Claim Reference"),
              b::Element(e::Required,    "Date")),

            d::LoopDef.build("N1", d::RepeatCount.bounded(4),
              b::Segment( 30, s:: N1, "Name", r::Situational, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Entity Identifier Code", b::Values("SU")),
                b::Element(e::Situational, "Name - Supplier"),
                b::Element(e::Situational, "Identification Code Qualifier", b::Values("92")),
                b::Element(e::Situational, "Identification Code - Supplier Code")),
              b::Segment( 80, s::PER, "Administrative Communications Contact", r::Situational, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Contact Function Code", b::Values("EN")),
                b::Element(e::Situational, "Name - Contact Name"),
                b::Element(e::Situational, "Communication Number Qualifier", b::Values("TE")),
                b::Element(e::Situational, "Communication Number")))),

          d::TableDef.detail("Detail",
            d::LoopDef.build("LX", d::RepeatCount.unbounded,
              b::Segment(10, s::LX, "Assigned Number", r::Required, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Assigned Number")),
              b::Segment(20, s::N9, "Reference Number - Receiver Claim Number", r::Required, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Reference Number Qualifier"),
                b::Element(e::Required,    "Reference Number - Receiver Claim Number")),
              b::Segment(21, s::N9, "Reference Number - Business Type", r::Required, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Reference Number Qualifier", b::Values("BE")),
                b::Element(e::Required,    "Reference Number - Business Type",
                  b::Values("AC","ES","ET","IS","MP","NS","NT","PM","PP","PR","RB","RC","RP","SP","TW"))),
              b::Segment(22, s::N9, "Reference Number - State Code", r::Required, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Reference Number Qualifier", b::Values("SL")),
                b::Element(e::Required,    "Reference Number - Sales Territory",
                  b::Values("AB","AK","AL","AR","AS","AZ","BC","BR","CA","CO","CT","DE","FL","GA","GU","HI",
                            "IA","ID","IL","IN","JD","KS","KW","KY","LA","MA","MB","MD","ME","MI","MN","MO",
                            "MP","MS","MT","NA","NB","NC","ND","NE","NF","NH","NJ","NL","NM","NS","NT","NU",
                            "NV","NW","NY","OH","OK","OM","ON","OR","PA","PE","PQ","PR","QC","QT","RI","S1",
                            "S2","SC","SD","SK","TK","TN","TW","TX","U1","U2","UT","VA","VI","VT","WA","WI",
                            "WV","WY","XX","YT"))),
              b::Segment(23, s::N9, "Reference Number - Adjustment Memo Number", r::Required, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Reference Number Qualifier", b::Values("AM")),
                b::Element(e::Required,    "Reference Number - Adjustment Memo Number")),
              b::Segment(24, s::N9, "Reference Number - Receiver Claim Number", r::Required, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Reference Number Qualifier", b::Values("D9")),
                b::Element(e::Required,    "Reference Number - Distributor's Claim Number")),
              b::Segment(25, s::N9, "Reference Number - Receiver Claim Number", r::Required, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Reference Number Qualifier", b::Values("SB")),
                b::Element(e::Required,    "Reference Number - Distributor Code")),
              b::Segment(26, s::N9, "Reference Number - Receiver Claim Number", r::Required, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Reference Number Qualifier", b::Values("88")),
                b::Element(e::Required,    "Reference Number - Distributor name")),
              b::Segment(27, s::N9, "Reference Number - Receiver Claim Number", r::Required, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Reference Number Qualifier", b::Values("BY")),
                b::Element(e::Required,    "Reference Number - Class Code Qualifier")),
              b::Segment(28, s::N9, "Reference Number - Receiver Claim Number", r::Required, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Reference Number Qualifier", b::Values("VG")),
                b::Element(e::Required,    "Reference Number - Claim Class Code Description")),
              b::Segment(29, s::N9, "Reference Number - Receiver Claim Number", r::Required, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Reference Number Qualifier", b::Values("MJ")),
                b::Element(e::Required,    "Reference Number - Major Model Series")),
              b::Segment(30, s::N9, "Reference Number - Receiver Claim Number", r::Required, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Reference Number Qualifier", b::Values("K6")),
                b::Element(e::Required,    "Reference Number - Major Model Description")),

              d::LoopDef.build("LIN", d::RepeatCount.unbounded,
                b::Segment( 32, s::LIN, "Item Identification", r::Required, d::RepeatCount.bounded(1),
                  b::Element(e::Situational,  "Assigned Identification"),
                  b::Element(e::Required,     "Product/Service ID Qualifier - Model Number", b::Values("MN")),
                  b::Element(e::Required,     "Product/Service ID - End Item Model Code"),
                  b::Element(e::Situational,  "Product/Service ID Qualifier", b::Values("VV")),
                  b::Element(e::Situational,  "Product/Service ID - Vehicle Identification Number (VIN)"),
                  b::Element(e::Situational,  "Product/Service ID Qualifier", b::Values("ES")),
                  b::Element(e::Situational,  "Product/Service ID - Engine Number"),
                  b::Element(e::Situational,  "Product/Service ID Qualifier", b::Values("EM")),
                  b::Element(e::Situational,  "Product/Service ID - Engine Model"),
                  b::Element(e::Situational,  "Product/Service ID Qualifier - Product ID", b::Values("PQ")),
                  b::Element(e::Situational,  "Product/Service ID - Primary Failed Part (PFP)"),
                  b::Element(e::Situational,  "Product/Service ID Qualifier", b::Values("RY")),
                  b::Element(e::Situational,  "Product/Service ID - Model Year"),
                  b::Element(e::Situational,  "Product/Service ID Qualifier", b::Values("PC")),
                  b::Element(e::Situational,  "Product/Service ID - Part Number Code and PNC Description"),
                  b::Element(e::Situational,  "Product/Service ID Qualifier", b::Values("PF")),
                  b::Element(e::Situational,  "Product/Service ID - Primary Failed Part Description")),
                b::Segment( 50, s::QTY, "Quantity", r::Required, d::RepeatCount.bounded(2),
                  b::Element(e::Situational,  "Quantity Qualifier"),
                  b::Element(e::Required,     "Quantity - Mileage"),
                  b::Element(e::Required,     "Unit or Basis for Measurement Code", b::Values("DH"))),
                b::Segment( 60, s::DTM, "Date/Time/Period", r::Required, d::RepeatCount.unbounded,
                  b::Element(e::Situational,  "Date/Time Qualifier", b::Values("006","094","128","194","214")),
                  b::Element(e::Required,     "Date"),
                  b::Element(e::Required,     "Century")),
                b::Segment( 100, s::SSS, "Special Services", r::Required, d::RepeatCount.unbounded,
                  b::Element(e::Required,    "Allowance or Charge Indicator", b::Values("C")),
                  b::Element(e::Required,    "Agency Qualifier Code", b::Values("AB")),
                  b::Element(e::Required,    "Special Services Code", b::Values("PP","SH","ZZ")),
                  b::Element(e::Situational, "Allowance or Charge Rate - Supplier Rate"),
                  b::Element(e::Situational, "Allowance or Charge Total Amount"),
                  b::Element(e::NotUsed,     ""),
                  b::Element(e::Situational, "Quantity - Supplier Amount"))),

              d::LoopDef.build("PRR", d::RepeatCount.unbounded,
                b::Segment( 170, s::PRR, "Problem Report", r::Required, d::RepeatCount.bounded(1),
                  b::Element(e::Situational,    "Assigned Identification"),
                  b::Element(e::Situational,    "Complaint Code"),
                  b::Element(e::Situational,    "Description")),
                b::Segment( 210, s::MSG, "Message Text", r::Required, d::RepeatCount.unbounded,
                  b::Element(e::Required,    "Free-Form Message Text - Tech Comment/Service Advisor Comment"))),

              d::LoopDef.build("REP", d::RepeatCount.unbounded,
                b::Segment( 310, s::REP, "Repair Action", r::Required, d::RepeatCount.bounded(1),
                  b::Element(e::Situational,    "Assigned Identification"),
                  b::Element(e::Situational,    "Product/Service ID Qualifier", b::Values("PN","RV","SV")),
                  b::Element(e::Situational,    "Product/Service ID - Vendor Part Number/Operation Number")),

                d::LoopDef.build("IT1", d::RepeatCount.bounded(1),
                  b::Segment( 400, s::IT1, "Baseline Item Data (Invoice)", r::Situational, d::RepeatCount.bounded(1),
                    b::Element(e::Situational,    "Assigned Identification"),
                    b::Element(e::Situational,    "Quantity Invoiced - Part Quantity/Labor Hours"),
                    b::Element(e::Situational,    "Unit or Basis for Measurement Code", b::Values("EA","LH")),
                    b::Element(e::Situational,    "Unit Price - Part Cost/Labor Cost")))),

              d::LoopDef.build("AMT", d::RepeatCount.bounded(1),
                b::Segment( 450, s::AMT, "Monetary Amount", r::Situational, d::RepeatCount.bounded(1),
                  b::Element(e::Required,    "Assigned Identification", b::Values("CC")),
                  b::Element(e::Required,    "Product/Service ID Qualifier"))))),

          d::TableDef.header("Summary",
            d::LoopDef.build("TDS", d::RepeatCount.bounded(1),
              b::Segment(361, s::TDS, "Total Monetary Value Summary", r::Situational, d::RepeatCount.bounded(1),
                b::Element(e::Required,    "Total Invoice Amount"))),

            b::Segment(40, 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
