# DAS: the source, in its own words. An ODCS v3 data contract, one per table.
# The shop's order lines. The shop is a PostgreSQL database, which das-cli has
# no source type for, so there is no das source file beside this contract; the
# demo loads the table into DuckDB as stage.sales_order_lines.
apiVersion: v3.0.0
version: 1.0.0
kind: DataContract
id: shop__sales_order_lines
schema:
  - name: sales_order_lines
    physicalName: shop__sales_order_lines
    description: >
      One row per book sold on an order. A line has no timestamp of its own:
      when it happened is the order's order_date. Lines are updated in place as
      they are fulfilled (there is no updated_at column).
    properties:
      - name: order_id
        logicalType: integer
        required: true
        primaryKey: true
        primaryKeyPosition: 1
        transformSourceObjects: [order_id]
        description: The order this line is on (sales_orders.order_id).
      - name: order_line_id
        logicalType: integer
        required: true
        primaryKey: true
        primaryKeyPosition: 2
        transformSourceObjects: [order_line_id]
        description: >
          Line number within the order. It restarts at 1 on every order, so a
          line is identified by order_id and order_line_id together.
      - name: product_id
        logicalType: integer
        required: true
        transformSourceObjects: [product_id]
        description: The catalog product (book) sold on the line (products.product_id).
      - name: quantity
        logicalType: integer
        required: true
        transformSourceObjects: [quantity]
        description: Number of copies sold on the line.
      - name: unit_price
        logicalType: number
        required: true
        transformSourceObjects: [unit_price]
        description: >
          Price per copy charged on this line, before discount and tax, in the
          order's currency (sales_orders.currency; every order in stage is USD).
          NUMERIC(10,2).
      - name: discount_amount
        logicalType: number
        required: false
        transformSourceObjects: [discount_amount]
        description: >
          Discount taken off the whole line (not per copy), in the order's
          currency. Defaults to 0.
      - name: tax_amount
        logicalType: number
        required: false
        transformSourceObjects: [tax_amount]
        description: >
          Sales tax charged on the line, in the order's currency. Defaults to 0;
          a NULL counts as 0 in line_total.
      - name: line_total
        logicalType: number
        required: false
        transformSourceObjects: [line_total]
        description: >
          What the line charged, tax included, in the order's currency (every
          order in stage is USD). Computed by the database, never written by the
          application: a generated column, (quantity * unit_price) -
          discount_amount + COALESCE(tax_amount, 0), NUMERIC(12,2). A NULL
          discount_amount makes it NULL.
      - name: fulfillment_status
        logicalType: string
        required: false
        transformSourceObjects: [fulfillment_status]
        description: >
          Where the line is in fulfillment. Values in the data: Processing,
          Shipped, Delivered. New lines default to Pending. Overwritten in place
          when the line moves on, so the table keeps no history of it.
customProperties:
  - property: das.resource
    value: sales_order_lines
  - property: das.models
    value: historized,latest
