collections:
  "{{ item.metadata.title }}":
    {%- set lstCollection = item.pmm.collection | unique | join(", ") %}
    {%- set lstList = item.pmm.list | unique | join(", ") | default("") %}
    {%- set lstShow = "" %}
    {%- set lstMovie = item.metadata | getCollectionGuidsByName("tmdb") | concat(item.pmm.movie) | unique | join(", ") %}
    {%- set lstLabels = item.metadata | getNamedCollectionLabels | concat(item.pmm.label) | unique | join(", ") %}
    variables: { 
      {%- if lstLabels %} label: "{{ lstLabels }}",{% endif %}
      {%- if item.pmm and item.pmm.sort.prefix %} sort_prefix: "{{item.pmm.sort.prefix}}",{% endif %}
      {%- if item.pmm and item.pmm.sort.order %} sort_order: "{{ item.pmm.sort.order }}",{% endif %}
      {%- if item.pmm and item.pmm.sort.separator %} sort_separator: "{{ item.pmm.sort.separator }}",{% endif %}
      {%- if lstMovie | length > 0 %} movie: "{{ lstMovie }}",{% endif %}
      {%- if lstShow | length > 0 %} show: "{{ lstShow }}",{% endif %}
      {%- if settings.thePosterDatabase.dbAssetUrl %} poster: {{ item.pmm.poster | default(settings.thePosterDatabase.dbAssetUrl, True) }}{% endif %} }
    template: [ 
      { name: tplCommonBase }, 
      { name: tplCommonCollection }, 
      { name: tplTMDBCollection{% if lstCollection | length > 0 %}, collection: "{{ lstCollection }}"{% endif %} }, 
      {%- if lstList | length > 0 %}{ name: tplTVDBCollection, list: "{{ lstList }}" }{% endif %}
    ]
    {%- if item.metadata.summary %}
    summary: |
      {{ item.metadata.summary.rstrip() }}{%- endif %}
    # tpdb: {{ item.metadata | generateTpDbSearchUrl }}
    # tmdb: https://www.themoviedb.org/search/collection?query={{ item.metadata.title | quote | urlencode}}
    # tvdb: https://thetvdb.com/search?menu%5Btype%5D=list&query={{ item.metadata.title | urlencode }}
    # imdb: https://www.imdb.com/find/?s=tt{% if item.metadata.subtype == 'movie' %}&ttype=ft{% elif item.metadata.subtype == 'show' %}&ttype=tv{% endif %}&q={{ item.metadata.title | urlencode }}
    # trakt: https://trakt.tv/search/lists?query={{ item.metadata.title | urlencode }}
    {% if item.metadata.childCount != 1 %}# {% endif %}collection_mode: hide
    {% if not item.pmm.trakt %}# {% endif %}trakt_list:
    {%- if not item.pmm.trakt %}
    #   -{% else %}
    {%- for t in item.pmm.trakt %}
       - {{ t }} {% endfor %}{% endif %}

########################################################################################################################
########################################################################################################################

{# external_templates:
  pmm: templates
  file: {{ settings.runtime.currentWorkingPathRelative }}/_templates/templates.yaml #}
templates:
  tplCommonBase:
    optional:
      - poster
    move_prefix: The
    sync_mode: sync
    url_poster: <<poster>>

  tplCommonCollection:
    default:
      sort_prefix: ""
      sort_order: ""
      sort_separator: ""
    optional:
      - label
    label: "PMM-U-<<label>>"
    item_label: "PMM-U-<<label>>"
    collection_order: release
    sort_title: <<sort_prefix>><<sort_separator>><<sort_order>><<sort_separator>><<collection_name>>

  tplTVDBCollection:
    optional:
      - list
      - show
      - movie
    tvdb_list: https://www.thetvdb.com/lists/<<list>>
    tvdb_list_details: https://www.thetvdb.com/lists/<<list>>
    tvdb_movie: <<movie>>
    tvdb_movie_details: <<movie>>
    tvdb_show: <<show>>
    tvdb_show_details: <<show>>

  tplTMDBCollection:
    optional:
      - collection
      - list
      - movie
      - show
    tmdb_collection: <<collection>>
    tmdb_collection_details: <<collection>>
    tmdb_list: <<list>>
    tmdb_list_details: <<list>>
    tmdb_movie: <<movie>>
    tmdb_movie_details: <<movie>>
    tmdb_show: <<show>>
    tmdb_show_details: <<show>>
