unit_tests:
  - name: test_audience_filter_restrictions
    description: >
      Test that fan location based restrictions are
      correctly applied
    model: AUDIENCE_FILTERS_AD_CAMPAIGN_DBT
    given:
      - input: ref('FAN_ARTIST_DBT')
        rows:
          - {
            fan_id: 'fan_0',
            vendor_id: 1,
            subaccount_id: 0,
            global_participant_id: 'gp_id1',
          }
          - {
              fan_id: 'fan_1',
              vendor_id: 1,
              subaccount_id: 0,
              global_participant_id: 'gp_id1',
            }
          - {
            fan_id: 'fan_2',
            vendor_id: 1,
            subaccount_id: 0,
            global_participant_id: 'gp_id1',
            }
          - {
            fan_id: 'fan_3',
            vendor_id: 1,
            subaccount_id: 0,
            global_participant_id: 'gp_id1',
            }
          - {
            fan_id: 'fan_4',
            vendor_id: 1,
            subaccount_id: 0,
            global_participant_id: 'gp_id1',
            }
      - input: ref('INT_SONGWHIP_FAN_CONSENT_DBT')
        rows:
          - {
            fan_id: 'fan_0',
            advertising_profiling: null,
            ip_location_based_marketing: 1,
            }
          - {
              fan_id: 'fan_1',
              advertising_profiling: 0,
              ip_location_based_marketing: 1,
            }
          - {
            fan_id: 'fan_2',
            advertising_profiling: 1,
            ip_location_based_marketing: 1,
            }
          - {
            fan_id: 'fan_3',
            advertising_profiling: 1,
            ip_location_based_marketing: 1,
            }
          - {
            fan_id: 'fan_4',
            advertising_profiling: 1,
            ip_location_based_marketing: 1,
            }
      - input: ref('AUDIENCE_FILTERS_BY_FAN_DBT')
        rows:
          - {
              fan_id: 'fan_0',
              dsp: ["SPOTIFY"],
              genre_list: null,
              fan_language_list: null,
              birth_month: null,
              country_iso2: 'NO',
              region_code: 'NO2',
              region: 'Innlandet',
              city_id: 1,
              longitude: null,
              latitude: null,
              retargeting_consent: true,
            }
          - {
              fan_id: 'fan_1',
              dsp: ["SPOTIFY"],
              genre_list: null,
              fan_language_list: null,
              birth_month: null,
              country_iso2: 'NO',
              region_code: 'NO1',
              region: 'Oslo',
              city_id: 4,
              longitude: null,
              latitude: null,
              retargeting_consent: true,
            }
          - {
            fan_id: 'fan_2',
            dsp: [ "DEEZER" ],
            genre_list: null,
            fan_language_list: null,
            birth_month: null,
            country_iso2: 'NO',
            region_code: 'NO1',
            region: 'Oslo',
            city_id: 1,
            longitude: null,
            latitude: null,
            retargeting_consent: true,
            }
          - {
            fan_id: 'fan_3',
            dsp: [ "DEEZER" ],
            genre_list: null,
            fan_language_list: null,
            birth_month: null,
            country_iso2: 'IE',
            region_code: 'IE1',
            region: 'Leinster',
            city_id: 1,
            longitude: null,
            latitude: null,
            retargeting_consent: true,
            }
          - {
            fan_id: 'fan_4',
            dsp: [ "DEEZER" ],
            genre_list: null,
            fan_language_list: null,
            birth_month: null,
            country_iso2: 'BE',
            region_code: 'BE1',
            region: 'Brussels',
            city_id: 1,
            longitude: null,
            latitude: null,
            retargeting_consent: true,
            }
      - input: ref('AUDIENCE_FILTERS_BY_FAN_ARTIST_ACCOUNT_DBT')
        rows:
          - {
              fan_id: 'fan_0',
              total_spend: 34,
              last_event_date: 2023-09-07 00:00:00-0,
              segment_name: 'CASUAL_FAN',
              email_consent: true,
              vendor_id: 1,
              subaccount_id: 0,
              global_participant_id: 'gp_id1',
            }
          - {
              fan_id: 'fan_1',
              total_spend: 100.5,
              last_event_date: 2024-11-07 00:00:00-0,
              segment_name: 'CASUAL_FAN',
              email_consent: true,
              vendor_id: 1,
              subaccount_id: 0,
              global_participant_id: 'gp_id1',
            }
          - {
            fan_id: 'fan_2',
            total_spend: 200.5,
            last_event_date: 2022-11-07 00:00:00-0,
            segment_name: 'CASUAL_FAN',
            email_consent: true,
            vendor_id: 1,
            subaccount_id: 0,
            global_participant_id: 'gp_id1',
          }
          - {
            fan_id: 'fan_3',
            total_spend: 44.5,
            last_event_date: 2022-12-07 00:00:00-0,
            segment_name: 'CASUAL_FAN',
            email_consent: true,
            vendor_id: 1,
            subaccount_id: 0,
            global_participant_id: 'gp_id1',
          }
          - {
            fan_id: 'fan_4',
            total_spend: 400.,
            last_event_date: 2024-11-07 00:00:00-0,
            segment_name: 'CASUAL_FAN',
            email_consent: false,
            vendor_id: 1,
            subaccount_id: 0,
            global_participant_id: 'gp_id1',
          }
      - input: ref('FAN_HEAVY_ROTATION_DBT')
        rows:
          - {
            fan_id: 'fan_0',
            heavy_rotation: 'IN',
            global_participant_id: 'gp_id1',
          }
          - {
              fan_id: 'fan_1',
              heavy_rotation: 'NOT_IN',
              global_participant_id: 'gp_id1',
            }
          - {
              fan_id: 'fan_2',
              heavy_rotation: 'IN',
              global_participant_id: 'gp_id1',
            }
          - {
              fan_id: 'fan_3',
              heavy_rotation: 'IN',
              global_participant_id: 'gp_id1',
            }
          - {
              fan_id: 'fan_4',
              heavy_rotation: 'NOT_IN',
              global_participant_id: 'gp_id1',
            }
      - input: ref('FAN_AGE_DBT')
        rows:
          - {
              fan_id: 'fan_1',
              age_range: 'FROM_24_TO_55'
            }
          - {
            fan_id: 'fan_2',
            age_range: 'FROM_24_TO_55'
            }
          - {
            fan_id: 'fan_3',
            age_range: 'FROM_13_TO_17'
          }
      - input: ref('INT_PRIMARY_FANS_DBT')
        rows:
          - {
            fan_id: 'fan_0',
            vendor_id: 1,
            subaccount_id: 0,
            global_participant_id: 'gp_id1',
          }
          - {
              fan_id: 'fan_1',
              vendor_id: 1,
              subaccount_id: 0,
              global_participant_id: 'gp_id1',
            }
          - {
            fan_id: 'fan_2',
            vendor_id: 1,
            subaccount_id: 0,
            global_participant_id: 'gp_id1',
          }
          - {
            fan_id: 'fan_3',
            vendor_id: 1,
            subaccount_id: 0,
            global_participant_id: 'gp_id1',
          }
          - {
            fan_id: 'fan_4',
            vendor_id: 1,
            subaccount_id: 0,
            global_participant_id: 'gp_id1',
          }
      - input: ref('FAN_LOCATION_DBT')
        rows:
          - {
              fan_id: 'fan_0',
              country_iso2: 'NO',
            }
          - {
              fan_id: 'fan_1',
              country_iso2: 'NO',
            }
          - {
            fan_id: 'fan_2',
            country_iso2: 'NO',
            }
          - {
            fan_id: 'fan_3',
            country_iso2: 'IE',
          }
          - {
            fan_id: 'fan_4',
            country_iso2: 'BE',
          }
    expect:
      rows:
          - {
            fan_id: 'fan_0',
            vendor_id: 1,
            subaccount_id: 0,
            global_participant_id: 'gp_id1',
            dsp: null,
            country_iso2: 'NO',
            region_code: 'NO2',
            region: 'Innlandet',
            city_id: 1,
            city_coordinates: null,
            total_spend: null,
            last_event_date: null,
            segment_name: 'UNSEGMENTED_FANS',
            heavy_rotation: null,
            is_primary_fan: 1
            }
          - {
            fan_id: 'fan_1',
            vendor_id: 1,
            subaccount_id: 0,
            global_participant_id: 'gp_id1',
            dsp: null,
            country_iso2: null,
            region_code: null,
            region: null,
            city_id: null,
            city_coordinates: null,
            total_spend: null,
            last_event_date: null,
            segment_name: 'UNSEGMENTED_FANS',
            heavy_rotation: null,
            is_primary_fan: 1
            }
          - {
            fan_id: 'fan_2',
            vendor_id: 1,
            subaccount_id: 0,
            global_participant_id: 'gp_id1',
            dsp: ['DEEZER'],
            country_iso2: 'NO',
            region_code: 'NO1',
            region: 'Oslo',
            city_id: 1,
            city_coordinates: null,
            total_spend: 200.5,
            last_event_date: 2022-11-07 00:00:00-0,
            segment_name: 'CASUAL_FAN',
            heavy_rotation: 'IN',
            is_primary_fan: 1
            }
  - name: test_global_audience_filter_restrictions
    description: >
      Test that fan location based restrictions are
      correctly applied to global model
    model: GLOBAL_AUDIENCE_FILTERS_ARTIST_AD_CAMPAIGN_DBT
    given:
      - input: ref('SME_ACCOUNT_DBT')
        rows:
          - {
            vendor_id: 1,
            INGEST_GLOBAL_DATA: 1,
          }
      - input: ref('FAN_ARTIST_DBT')
        rows:
          - {
            fan_id: 'fan_0',
            vendor_id: 1,
            global_participant_id: 'gp_id2',
            }
          - {
              fan_id: 'fan_1',
              vendor_id: 1,
              global_participant_id: 'gp_id2',
            }
          - {
            fan_id: 'fan_2',
            vendor_id: 1,
            global_participant_id: 'gp_id2',
            }
          - {
            fan_id: 'fan_3',
            vendor_id: 1,
            global_participant_id: 'gp_id2',
            }
          - {
            fan_id: 'fan_4',
            vendor_id: 1,
            global_participant_id: 'gp_id2',
            }
      - input: ref('INT_SONGWHIP_FAN_CONSENT_DBT')
        rows:
          - {
            fan_id: 'fan_0',
            advertising_profiling: null,
            ip_location_based_marketing: 1,
            }
          - {
              fan_id: 'fan_1',
              advertising_profiling: 0,
              ip_location_based_marketing: 1,
            }
          - {
            fan_id: 'fan_2',
            advertising_profiling: 1,
            ip_location_based_marketing: 1,
            }
          - {
            fan_id: 'fan_3',
            advertising_profiling: 1,
            ip_location_based_marketing: 1,
            }
          - {
            fan_id: 'fan_4',
            advertising_profiling: 1,
            ip_location_based_marketing: 1,
            }
      - input: ref('AUDIENCE_FILTERS_BY_FAN_DBT')
        rows:
          - {
              fan_id: 'fan_0',
              dsp: ["SPOTIFY"],
              genre_list: null,
              fan_language_list: null,
              birth_month: null,
              country_iso2: 'NO',
              region_code: 'NO2',
              region: 'Innlandet',
              city_id: 1,
              longitude: null,
              latitude: null,
              retargeting_consent: true,
            }
          - {
              fan_id: 'fan_1',
              dsp: ["SPOTIFY"],
              genre_list: null,
              fan_language_list: null,
              birth_month: null,
              country_iso2: 'NO',
              region_code: 'NO1',
              region: 'Oslo',
              city_id: 4,
              longitude: null,
              latitude: null,
              retargeting_consent: true,
            }
          - {
            fan_id: 'fan_2',
            dsp: [ "DEEZER" ],
            genre_list: null,
            fan_language_list: null,
            birth_month: null,
            country_iso2: 'NO',
            region_code: 'NO1',
            region: 'Oslo',
            city_id: 1,
            longitude: null,
            latitude: null,
            retargeting_consent: true,
            }
          - {
            fan_id: 'fan_3',
            dsp: [ "DEEZER" ],
            genre_list: null,
            fan_language_list: null,
            birth_month: null,
            country_iso2: 'IE',
            region_code: 'IE1',
            region: 'Leinster',
            city_id: 1,
            longitude: null,
            latitude: null,
            retargeting_consent: true,
            }
          - {
            fan_id: 'fan_4',
            dsp: [ "DEEZER" ],
            genre_list: null,
            fan_language_list: null,
            birth_month: null,
            country_iso2: 'BE',
            region_code: 'BE1',
            region: 'Brussels',
            city_id: 1,
            longitude: null,
            latitude: null,
            retargeting_consent: true,
            }
      - input: ref('GLOBAL_AUDIENCE_FILTERS_BY_FAN_ARTIST_DBT')
        rows:
          - {
              fan_id: 'fan_0',
              total_spend: 34,
              last_event_date: 2023-09-07 00:00:00-0,
              segment_name: 'CASUAL_FAN',
              email_consent: true,
              global_participant_id: 'gp_id2',
            }
          - {
              fan_id: 'fan_1',
              total_spend: 100.5,
              last_event_date: 2024-11-07 00:00:00-0,
              segment_name: 'CASUAL_FAN',
              email_consent: true,
              global_participant_id: 'gp_id2',
            }
          - {
            fan_id: 'fan_2',
            total_spend: 200.5,
            last_event_date: 2022-11-07 00:00:00-0,
            segment_name: 'CASUAL_FAN',
            email_consent: true,
            global_participant_id: 'gp_id2',
          }
          - {
            fan_id: 'fan_3',
            total_spend: 44.5,
            last_event_date: 2022-12-07 00:00:00-0,
            segment_name: 'CASUAL_FAN',
            email_consent: true,
            global_participant_id: 'gp_id2',
          }
          - {
            fan_id: 'fan_4',
            total_spend: 400.,
            last_event_date: 2024-11-07 00:00:00-0,
            segment_name: 'CASUAL_FAN',
            email_consent: false,
            global_participant_id: 'gp_id2',
          }
      - input: ref('FAN_HEAVY_ROTATION_DBT')
        rows:
          - {
            fan_id: 'fan_0',
            heavy_rotation: 'IN',
            global_participant_id: 'gp_id2',
          }
          - {
              fan_id: 'fan_1',
              heavy_rotation: 'NOT_IN',
              global_participant_id: 'gp_id2',
            }
          - {
              fan_id: 'fan_2',
              heavy_rotation: 'IN',
              global_participant_id: 'gp_id2',
            }
          - {
              fan_id: 'fan_3',
              heavy_rotation: 'IN',
              global_participant_id: 'gp_id2',
            }
          - {
              fan_id: 'fan_4',
              heavy_rotation: 'NOT_IN',
              global_participant_id: 'gp_id2',
            }
      - input: ref('FAN_AGE_DBT')
        rows:
          - {
              fan_id: 'fan_1',
              age_range: 'FROM_24_TO_55'
            }
          - {
            fan_id: 'fan_2',
            age_range: 'FROM_24_TO_55'
            }
          - {
            fan_id: 'fan_3',
            age_range: 'FROM_13_TO_17'
          }
      - input: ref('INT_PRIMARY_FANS_DBT')
        rows:
          - {
            fan_id: 'fan_0',
            vendor_id: 1,
            global_participant_id: 'gp_id2',
          }
          - {
              fan_id: 'fan_1',
              vendor_id: 1,
              global_participant_id: 'gp_id2',
            }
          - {
            fan_id: 'fan_2',
            vendor_id: 1,
            global_participant_id: 'gp_id2',
          }
          - {
            fan_id: 'fan_3',
            vendor_id: 1,
            global_participant_id: 'gp_id2',
          }
          - {
            fan_id: 'fan_4',
            vendor_id: 1,
            global_participant_id: 'gp_id2',
          }
      - input: ref('FAN_LOCATION_DBT')
        rows:
          - {
              fan_id: 'fan_0',
              country_iso2: 'NO',
            }
          - {
              fan_id: 'fan_1',
              country_iso2: 'NO',
            }
          - {
            fan_id: 'fan_2',
            country_iso2: 'NO',
            }
          - {
            fan_id: 'fan_3',
            country_iso2: 'IE',
          }
          - {
            fan_id: 'fan_4',
            country_iso2: 'BE',
          }
    expect:
      rows:
          - {
            fan_id: 'fan_0',
            global_participant_id: 'gp_id2',
            dsp: null,
            country_iso2: 'NO',
            region_code: 'NO2',
            region: 'Innlandet',
            city_id: 1,
            city_coordinates: null,
            total_spend: null,
            last_event_date: null,
            segment_name: 'UNSEGMENTED_FANS',
            heavy_rotation: null,
            is_primary_fan: 1
            }
          - {
            fan_id: 'fan_1',
            global_participant_id: 'gp_id2',
            dsp: null,
            country_iso2: null,
            region_code: null,
            region: null,
            city_id: null,
            city_coordinates: null,
            total_spend: null,
            last_event_date: null,
            segment_name: 'UNSEGMENTED_FANS',
            heavy_rotation: null,
            is_primary_fan: 1
            }
          - {
            fan_id: 'fan_2',
            global_participant_id: 'gp_id2',
            dsp: ['DEEZER'],
            country_iso2: 'NO',
            region_code: 'NO1',
            region: 'Oslo',
            city_id: 1,
            city_coordinates: null,
            total_spend: 200.5,
            last_event_date: 2022-11-07 00:00:00-0,
            segment_name: 'CASUAL_FAN',
            heavy_rotation: 'IN',
            is_primary_fan: 1
            }
