PREFIX gesli: <https://gesli.example/ontology#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?quote ?quoteNo ?validFrom ?validTo ?currency ?supplierCostAmount
       ?offering ?offeringCode ?offeringChannel ?agencyLevel ?capacityCommitment
       ?capacityAvailable ?supportsDangerousGoods ?dangerousGoodsOnly ?bookingSuccessRate ?spaceReleaseSuccessRate
       ?supplier ?supplierName ?supplierActive
       ?product ?productCode ?productName ?brandName ?transportMode ?serviceForm ?routeType
       ?originLocation ?destinationLocation ?estimatedTransitDays
       ?schedule ?scheduleCode ?documentCutoffTime ?estimatedDepartureTime ?estimatedArrivalTime
       ?etdAtdOnTimeRate ?etaAtaOnTimeRate
WHERE {
  ?quote a gesli:SupplierQuote ;
         gesli:quoteNo ?quoteNo ;
         gesli:quotedForOffering ?offering ;
         gesli:supplierCostAmount ?supplierCostAmount ;
         gesli:currency ?currency .

  ?offering gesli:offeredBySupplier ?supplier ;
            gesli:offeringProduct ?product .
  ?supplier rdfs:label ?supplierName .
  ?product gesli:productCode ?productCode ;
           gesli:productName ?productName ;
           gesli:transportMode ?transportMode .

  OPTIONAL { ?quote gesli:validFrom ?validFrom . }
  OPTIONAL { ?quote gesli:validTo ?validTo . }
  OPTIONAL { ?offering gesli:offeringCode ?offeringCode . }
  OPTIONAL { ?offering gesli:offeringChannel ?offeringChannel . }
  OPTIONAL { ?offering gesli:agencyLevel ?agencyLevel . }
  OPTIONAL { ?offering gesli:capacityCommitment ?capacityCommitment . }
  OPTIONAL { ?offering gesli:capacityAvailable ?capacityAvailable . }
  OPTIONAL { ?offering gesli:supportsDangerousGoods ?supportsDangerousGoods . }
  OPTIONAL { ?offering gesli:dangerousGoodsOnly ?dangerousGoodsOnly . }
  OPTIONAL { ?offering gesli:bookingSuccessRate ?bookingSuccessRate . }
  OPTIONAL { ?offering gesli:spaceReleaseSuccessRate ?spaceReleaseSuccessRate . }
  OPTIONAL { ?supplier gesli:isActivePartner ?directSupplierActive . }
  OPTIONAL {
    ?supplier gesli:hasBusinessPartnerBasicInfo ?supplierBasic .
    ?supplierBasic gesli:isActivePartner ?basicSupplierActive .
  }
  BIND(COALESCE(?directSupplierActive, ?basicSupplierActive, true) AS ?supplierActive)

  OPTIONAL { ?product gesli:serviceForm ?serviceForm . }
  OPTIONAL { ?product gesli:routeType ?routeType . }
  OPTIONAL { ?product gesli:originLocation ?originLocation . }
  OPTIONAL { ?product gesli:destinationLocation ?destinationLocation . }
  OPTIONAL { ?product gesli:estimatedTransitDays ?estimatedTransitDays . }
  OPTIONAL {
    ?product gesli:hasServiceBrand ?brand .
    ?brand gesli:brandName ?brandName .
  }
  OPTIONAL {
    ?product gesli:hasProductPerformanceProfile ?performance .
    OPTIONAL { ?performance gesli:etdAtdOnTimeRate ?etdAtdOnTimeRate . }
    OPTIONAL { ?performance gesli:etaAtaOnTimeRate ?etaAtaOnTimeRate . }
  }
  OPTIONAL {
    ?quote gesli:quoteAppliesToSchedule ?schedule .
    OPTIONAL { ?schedule gesli:scheduleCode ?scheduleCode . }
    OPTIONAL { ?schedule gesli:documentCutoffTime ?documentCutoffTime . }
    OPTIONAL { ?schedule gesli:estimatedDepartureTime ?estimatedDepartureTime . }
    OPTIONAL { ?schedule gesli:estimatedArrivalTime ?estimatedArrivalTime . }
  }
}
ORDER BY ?supplierCostAmount ?supplierName
