view: release_dms_restriction_snowflake {
  sql_table_name: orchard_app_reporting_v2.art_relations_prod_art_relations.release_dms_restriction ;;

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

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

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

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

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

#   measure: concat_count {
#     label: "Count Restrictions (Labeled)"
#     type: string
#     sql: IFF(COUNT(DISTINCT restriction_id) = 1,
#       '1 Store/Territory Restriction', CONCAT(COUNT(DISTINCT restriction_id), ' Store/Territory Restrictions')) ;;
#     html: {% if value == '0 Store/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 (${rdr_store.customer_name}||' '||${rdr_country.country_code}), ', ') ;;
  }

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