# ----------------------------------------------------------------------------
#                         TABLE DESCRIPTION
# ----------------------------------------------------------------------------
name: scenass_population
title: Population
description: >
  Population projections by 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
  # ----------------------------------------------------------------------------
  primaryKey: [scenario_group, scenario_name, scenario_variant, country, year]

  foreignKeys:
    - fields: country
      reference:
        resource: dim_iso_region
        fields: id
    - fields: [scenario_group, scenario_name, scenario_variant]
      reference:
        resource: dim_scenario
        fields: [group, name, variant]

  # ----------------------------------------------------------------------------
  #                  FRICTIONLESS FIELDS/COLUMNS
  # ----------------------------------------------------------------------------
  fields:
    - name: scenario_group
      type: string
      title: Scenario Group
      description: Scenario group

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

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

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

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

    - name: country
      type: string
      title: Country Code
      description: ISO 3166-1 alpha-2 country code

    - name: value
      type: number
      title: Value
      description: Population in the specified unit for the given scenario, scenario variant, country, and year
      constraints:
        required: true
        minimum: 0
