# DAB: an excerpt of the bookstore's business model, 5 of its 42 entities (customer, order, author, book, order_line) and the 4 relationships among them, copied verbatim.
model:
  id: BOOK_RETAILER_MODEL
  name: BookRetailerModel
  definition: Unified data of a multi-channel book retailer, every source system included
  description: Customers, catalog, orders and order lines, inventory, procurement, shipping, payments, returns, staff, marketing, service, and audit, historized for time-travel analytics

  entities:
    - id: customer
      name: customer
      definition: Customer who places orders
      description: Unified customer data from customers table and address snapshots
      attributes:
        - id: customer_id
          name: customer_id
          definition: Unique customer identifier
          type: STRING

        - id: customer_name
          name: customer_name
          definition: Full name of the customer
          type: STRING
          effective_timestamp: true

        - id: customer_email
          name: customer_email
          definition: Primary email address
          type: STRING
          effective_timestamp: true

        - id: customer_status
          name: customer_status
          definition: Account status (Active, Inactive, Suspended)
          type: STRING
          effective_timestamp: true

        - id: customer_city
          name: customer_city
          definition: City where customer is located
          type: STRING
          effective_timestamp: true

        - id: customer_state
          name: customer_state
          definition: State where customer is located
          type: STRING
          effective_timestamp: true

        - id: customer_loyalty_tier
          name: customer_loyalty_tier
          definition: Loyalty program tier level (Bronze, Silver, Gold, Platinum)
          type: STRING
          effective_timestamp: true

    - id: order
      name: order
      definition: Purchase order
      description: Orders placed by customers
      attributes:
        - id: order_id
          name: order_id
          definition: Unique order identifier
          type: STRING

        - id: order_status
          name: order_status
          definition: Current order status
          type: STRING
          effective_timestamp: true

        - id: order_size
          name: order_size
          definition: Order size class (SMALL, MEDIUM, LARGE)
          description: "Business rule: LARGE >= 100, MEDIUM >= 50, else SMALL"
          type: STRING
          effective_timestamp: true

        - id: order_purchase_ts
          name: order_purchase_ts
          definition: When order was placed
          type: START_TIMESTAMP

        - id: order_value
          name: order_value
          definition: Total monetary value of the order
          description: Amount and currency bundled as an atomic concept
          effective_timestamp: true
          group:
            - id: order_value_amount
              name: order_value_amount
              definition: Monetary amount
              type: NUMBER
            - id: order_value_currency
              name: order_value_currency
              definition: Currency code (ISO 4217, e.g. USD, EUR)
              type: UNIT

    - id: author
      name: author
      definition: Person credited as the writer of one or more books
      description: Catalog dimension. A book can have several authors (co-authorship) and an author can write several books.
      attributes:
        - id: author_id
          name: author_id
          definition: Unique author identifier
          type: STRING

        - id: author_name
          name: author_name
          definition: Name the author publishes under
          type: STRING
          effective_timestamp: true

        - id: author_website
          name: author_website
          definition: Public website of the author
          type: STRING
          effective_timestamp: true

        - id: author_country
          name: author_country
          definition: Country the author is associated with (ISO 3166-1 alpha-2)
          description: Not present in stage; carried as NULL until a source exists
          type: STRING
          effective_timestamp: true

        - id: author_status
          name: author_status
          definition: Publishing status (Active, Retired, Deceased)
          description: Not present in stage; carried as NULL until a source exists
          type: STRING
          effective_timestamp: true

    - id: book
      name: book
      definition: Title in the catalog that can be sold
      description: One row per sellable edition. Format is part of the identity, so a hardcover and a paperback of the same title are two books.
      attributes:
        - id: book_id
          name: book_id
          definition: Unique book identifier
          type: STRING

        - id: book_isbn
          name: book_isbn
          definition: ISBN-13 of the edition
          type: STRING

        - id: book_title
          name: book_title
          definition: Title as printed on the cover
          type: STRING
          effective_timestamp: true

        - id: book_format
          name: book_format
          definition: Physical or digital form (Hardcover, Paperback, Ebook, Audiobook)
          type: STRING
          effective_timestamp: true

        - id: book_genre
          name: book_genre
          definition: Primary category the book is filed under
          description: The primary assignment in the catalog's category table
          type: STRING
          effective_timestamp: true

        - id: book_edition
          name: book_edition
          definition: Edition label of the printing (First Edition, Reprint, ...)
          type: STRING
          effective_timestamp: true

        - id: book_language
          name: book_language
          definition: Language of the text (ISO 639-1 code, e.g. en, es, fr)
          type: STRING

        - id: book_publisher
          name: book_publisher
          definition: Publishing house of the edition
          description: Name resolved from the publisher master data
          type: STRING
          effective_timestamp: true

        - id: book_publisher_id
          name: book_publisher_id
          definition: Identifier of the publishing house
          type: STRING
          effective_timestamp: true

        - id: book_publication_ts
          name: book_publication_ts
          definition: Date the edition was published
          type: START_TIMESTAMP

        - id: book_page_count
          name: book_page_count
          definition: Number of pages; null for audiobooks
          type: NUMBER

        - id: book_status
          name: book_status
          definition: Availability status (Preorder, In Print, Out of Print, Inactive)
          description: "Business rule: discontinued_date set = Out of Print; publication in the future = Preorder; is_active = In Print; else Inactive"
          type: STRING
          effective_timestamp: true

        - id: book_list_price
          name: book_list_price
          definition: Recommended retail price of the edition
          description: Amount and currency bundled as an atomic concept. Price actually charged lives on order_line.
          effective_timestamp: true
          group:
            - id: book_list_price_amount
              name: book_list_price_amount
              definition: Monetary amount
              type: NUMBER
            - id: book_list_price_currency
              name: book_list_price_currency
              definition: Currency code (ISO 4217, e.g. USD, EUR)
              type: UNIT

    - id: order_line
      name: order_line
      definition: One book sold on one order
      description: Line grain of an order. Revenue, quantity, and returns are measured here; order holds the header total.
      attributes:
        - id: order_line_id
          name: order_line_id
          definition: Unique order line identifier
          type: STRING

        - id: order_line_status
          name: order_line_status
          definition: Fulfillment status of the line (Processing, Shipped, Delivered)
          type: STRING
          effective_timestamp: true

        - id: order_line_quantity
          name: order_line_quantity
          definition: Number of copies sold on the line
          type: NUMBER
          effective_timestamp: true

        - id: order_line_unit_price
          name: order_line_unit_price
          definition: Price per copy charged at the time of sale
          description: Captured on the order line because the list price on book changes over time.
          effective_timestamp: true
          group:
            - id: order_line_unit_price_amount
              name: order_line_unit_price_amount
              definition: Monetary amount
              type: NUMBER
            - id: order_line_unit_price_currency
              name: order_line_unit_price_currency
              definition: Currency code (ISO 4217, e.g. USD, EUR)
              type: UNIT

        - id: order_line_discount
          name: order_line_discount
          definition: Discount deducted from the line
          effective_timestamp: true
          group:
            - id: order_line_discount_amount
              name: order_line_discount_amount
              definition: Monetary amount
              type: NUMBER
            - id: order_line_discount_currency
              name: order_line_discount_currency
              definition: Currency code (ISO 4217, e.g. USD, EUR)
              type: UNIT

        - id: order_line_tax
          name: order_line_tax
          definition: Sales tax charged on the line
          effective_timestamp: true
          group:
            - id: order_line_tax_amount
              name: order_line_tax_amount
              definition: Monetary amount
              type: NUMBER
            - id: order_line_tax_currency
              name: order_line_tax_currency
              definition: Currency code (ISO 4217, e.g. USD, EUR)
              type: UNIT

        - id: order_line_amount
          name: order_line_amount
          definition: Amount charged for the line, tax included
          description: "Business rule: order_line_quantity * order_line_unit_price_amount - order_line_discount_amount + order_line_tax_amount, as carried in the source line total"
          effective_timestamp: true
          group:
            - id: order_line_amount_amount
              name: order_line_amount_amount
              definition: Monetary amount
              type: NUMBER
            - id: order_line_amount_currency
              name: order_line_amount_currency
              definition: Currency code (ISO 4217, e.g. USD, EUR)
              type: UNIT

  relationships:
    - name: is_placed_by
      definition: Order is placed by a customer
      description: "Cardinality: many-to-one. Each order is placed by exactly one customer; a customer places zero or more orders."
      source_entity_id: order
      target_entity_id: customer

    - name: is_written_by
      definition: Book is written by an author; a book may have several authors
      description: "Cardinality: many-to-many. A book has one or more authors; an author has one or more books."
      source_entity_id: book
      target_entity_id: author

    - name: is_part_of
      definition: Order line belongs to an order
      description: "Cardinality: many-to-one. Each order line belongs to exactly one order; an order has one or more lines."
      source_entity_id: order_line
      target_entity_id: order

    - name: is_of
      definition: Order line sells a book
      description: "Cardinality: many-to-one. Each order line sells exactly one book; a book appears on zero or more lines."
      source_entity_id: order_line
      target_entity_id: book
