view: release_territory_restriction_snowflake {
  sql_table_name: orchard_app_reporting_v2.art_relations_prod_art_relations.release_territory_restriction ;;

  dimension: restriction_id {
    hidden: yes
    primary_key: yes
    type: number
    sql: ${TABLE}.restriction_id ;;
  }

  dimension: country_id {
    hidden: yes
    type: number
    sql: ${TABLE}.country_id ;;
  }

  dimension: release_id {
    hidden: yes
    type: number
    sql: ${TABLE}.release_id ;;
  }

  dimension: upc {
    hidden: yes
    type: number
    sql: ${TABLE}.upc ;;
  }

  measure: count {
    label: "Count Restrictions"
    type: number
    sql: COUNT(DISTINCT ${TABLE}.country_id) ;;
  }

#   measure: concat_count {
#     label: "Count Restrictions (Labeled)"
#     type: string
#     sql: IFF(COUNT(DISTINCT ${TABLE}.country_id) = 1,
#       '1 Territory Restriction', CONCAT(COUNT(DISTINCT ${TABLE}.country_id), ' Territory Restrictions')) ;;
#     html: {% if value == '0 Territory Restrictions' %}
#       <p style="color: black; background-color: #99e699; font-size:100%;">{{ rendered_value }}</p>
#       {% else %} <p style="color: black; background-color: #ff8680; font-size:100%;">{{ rendered_value }}</p>
#     {% endif %} ;;
#   }

  measure: list_restrictions {
    type: string
    sql: LISTAGG(DISTINCT ${rtr_country.name}, ', ') WITHIN GROUP (ORDER BY ${rtr_country.name}) ;;
  }

  measure: list_restrictions_pipe_separated {
    label: "List Restrictions ('|' Separated)"
    type: string
    sql: listagg(distinct(${rtr_country.abbrivation}),'|') within group (order by ${rtr_country.abbrivation}) ;;
  }

  set: detail {
    fields: [
      country_id,
      release_id,
      restriction_id,
      upc
    ]
  }

}