# ----------------------------------------------------------------------------
#                         TABLE DESCRIPTION
# ----------------------------------------------------------------------------
name: scenass_passenger_transport_useful_energy_demand
title: Useful energy demand in passenger transport
description: >
  Useful energy demand in passenger transport by transport mode, year, and variant. Used as assumptions for scenario runs.
contract_type: ValueVariable
# ----------------------------------------------------------------------------
#                ----- Frictionless Table Schema -----
# ----------------------------------------------------------------------------
tableschema:

  # ----------------------------------------------------------------------------
  #                SEMANTIC FIELD DESCRIPTION
  # ----------------------------------------------------------------------------
  fieldDescriptors:
    - field: value
      type: value
    - field: year
      type: time
      frequency: yearly
    - field: country
      type: location
      locationType: country

  # ----------------------------------------------------------------------------
  #                        FOREIGN KEY CONSTRAINTS
  # ----------------------------------------------------------------------------
  # A list of field names that are jointly unique. As it is an assumption table,
  # it include the scenario information. E.g.
  primaryKey:
    [scenario_group, scenario_name, scenario_variant, mode, year, country]

  # put the reference to cited fields (country left as example)
  # see: https://specs.frictionlessdata.io/table-schema/#foreign-keys
  foreignKeys:
    - fields: country
      reference:
        resource: dim_iso_region
        fields: id
    - fields: mode
      reference:
        resource: dim_trn_mode_private
        fields: id
    - fields: [scenario_group, scenario_name, scenario_variant]
      reference:
        resource: dim_scenario
        fields: [group, name, variant]

  # ----------------------------------------------------------------------------
  #                  FRICTIONLESS FIELDS/COLUMNS
  # ----------------------------------------------------------------------------
  fields:
    # its an assumption table, so keep the scenario information: group, scenario_name, scenario_variant
    # will become foreign keys. I will add that later
    - name: scenario_group
      type: string
      title: Scenario Group
      description: Scenario group
      constraints:
        required: true
        maxLength: 100

    - name: scenario_name
      type: string
      title: Scenario Name
      description: Scenario name

    - name: scenario_variant
      type: string
      title: Scenario Variant
      description: Scenario variant

    # enter the fields of the table (left year and country_id as example)
    - name: mode
      type: string
      title: Transport Mode
      description: Passenger transport mode
      constraints:
        required: true

    - name: unit
      type: string
      title: Unit
      description: Measurement unit of the reported value
      constraints:
        required: true
        maxLength: 16

    - name: country
      type: string
      title: Country Code
      description: ISO 3166-1 alpha-2 country code
      constraints:
        required: true
        maxLength: 8

    - name: year
      type: integer
      title: Year
      description: Year to which the data value applies
      constraints:
        required: true
        minimum: 1900
        maximum: 2100

    - name: value
      type: number
      title: Value
      description: Useful energy demand for passenger transport in the specified unit for the given scenario, scenario variant, transport mode, country, and year
      constraints:
        required: true
        minimum: 0
