view: orch_app_ar_track {
  sql_table_name: orchard_app_reporting_v2.art_relations_prod_art_relations.track ;;

  dimension: tuid {
    label: "TUID"
    description: "Track Unique Identifier (TUID)"
    type: number
    sql: ${TABLE}.id ;;
    value_format: "0"
  }

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

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

  dimension: isrc {
    label: "ISRC"
    type: string
    sql: ${TABLE}.isrc ;;
  }

  dimension: track_name {
    type: string
    sql: ${TABLE}.track_name ;;
    link: {
      label: "Track View"
      url:
      "

      {% if _explore._name == 'int_prod_daily_spikes_us' %}
      https://theorchard.looker.com/dashboards/1283?ISRC={{ orch_app_ar_track.isrc._value }}&Label%20ID={{orch_app_ar_vendor.vendor_id._value }}&Country%20Name={{_filters['transaction_country.name']}}

      {% elsif _explore._name == 'int_prod_daily_top_content' %}

      https://theorchard.looker.com/dashboards/1283?ISRC={{ orch_app_ar_track.isrc._value }}&Label%20ID={{orch_app_ar_vendor.vendor_id._value }}&Territory%20Group={{_filters['int_prod_daily_top_content.country']}}

      {% elsif _explore._name == 'int_prod_streaming_totals_last_sales_week' %}

      https://theorchard.looker.com/dashboards/1283?ISRC={{ orch_app_ar_track.isrc._value }}&Label%20ID={{orch_app_ar_vendor.vendor_id._value }}

      {% else %}


      {% endif %}
      "
    }
  }
# to be added back when necessary
# {% if _explore._name == 'facts_prod_fact_analytics_v2' %}
#       https://theorchard.looker.com/dashboards/1283?ISRC={{ orch_app_ar_track.isrc._value }}&Label%20ID={{facts_prod_fact_analytics_v2.labelid._value }}&Country%20Name={{_filters['transaction_country.name']}}&Territory%20Group={{_filters['int_prod_territory_grouping.territory_group']}}

  dimension: track_type {
    type: string
    sql: ${TABLE}.track_type ;;
    description: "'music' or 'video'"
  }

  dimension: duration {
    type: string
    sql: zeroifnull(${TABLE}.length_minute)||':'||RIGHT('0'||zeroifnull(${TABLE}.length_seconds),2) ;;
  }

  dimension: duration_in_minutes  {
    type: number
    sql: zeroifnull(${TABLE}.length_minute) ;;
    label: "Track Length in Minutes"
  }

  dimension:  duration_in_seconds{
    type: number
    sql: zeroifnull(${TABLE}.length_seconds) ;;
    label: "Track Length in Seconds"

  }

  dimension: duration_total_in_seconds {
    type: number
    sql: (zeroifnull(${TABLE}.length_minute))* 60 +  zeroifnull(${TABLE}.length_seconds) ;;
    label: "Track Length (Total) in Seconds"
  }

  dimension: position {
    type: number
    sql: ${TABLE}.track_id ;;
  }

  dimension: p_line {
    type: string
    sql: ${TABLE}.p_line ;;
    group_label: "P Line"
  }

  dimension: p_line_year {
    type: string
    sql: TRY_TO_NUMERIC(LEFT(TRIM(${TABLE}.p_line),4)) ;;
    group_label: "P Line"
    label: "P Line Year"
  }

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

  dimension: track_version {
    type: string
    sql: ${TABLE}.version;;
  }

  dimension: volume {
    type: number
    sql: ${TABLE}.cd ;;
  }

  dimension: meta_language {
    type: string
    sql: ${TABLE}.meta_language ;;
    hidden: yes
  }

  measure: number_of_tracks {
    type: count_distinct
    sql: ${TABLE}.id;;
  }

  dimension: us_publishing_obligation {
    type: string
    sql:  ${TABLE}.us_publishing_obligation ;;
    label: "US Publishing Obligation"
  }

  dimension: offer_type {
    type: string
    sql: ${TABLE}.offer_type ;;
  }
}