#
#  Plex Extension Framework
#  Copyright (C) 2008-2012 Plex, Inc. (James Clarke, Elan Feingold). All Rights Reserved.
#

from common_records import MetadataRecord, Concert, Person
from common_templates import MediaProxyContainer
from extra_models import MusicVideo, BehindTheScenes, Interview, LiveMusicVideo, LyricMusicVideo, ConcertVideo

class Track(MetadataRecord):
  name                      = Template.String()
  name.exclude_from_interface
  
  
  # Interface settings
  
  xml_tag                   = 'Track'
  xml_attributes            =  dict(type = 'track')
  
  key                       = Template.String()
  key.is_synthetic

  title                     = Template.String()

  title_sort                = Template.String()

  rating_key                = Template.String()
  rating_key.is_synthetic
  
  index                     = Template.Integer()

  disc_index                = Template.Integer()
  track_index               = Template.Integer()

  artist                    = Template.String()
  artist.is_synthetic
  artist.xml_attr_name      = 'grandparentTitle'
  
  album                     = Template.String()
  album.is_synthetic
  album.xml_attr_name       = 'parentTitle'
  
  genres                    = Template.Set(Template.String())
  genres.xml_tag            = 'Genre'
  genres.is_synthetic

  tags                      = Template.Set(Template.String())
  tags.xml_tag              = 'Tag'

  duration                  = Template.Integer()            
  duration.is_synthetic

  tempo                     = Template.Integer()            

  moods                     = Template.Set(Template.String())
  moods.xml_tag             = 'Mood'

  rating                    = Template.Float()
  rating_count              = Template.Integer()              

  thumb                     = Template.String()
  thumb.is_synthetic
  
  summary                   = Template.String()
  summary.is_synthetic
  
  art_url                   = Template.String()
  art_url.is_synthetic
  art_url.synthetic_name    = 'art'

  originally_available_at   = Template.Date()
  originally_available_at.is_synthetic
  
  source_title              = Template.String()
  source_title.is_synthetic

  original_title            = Template.String()

  extras                    = Template.ObjectContainer(MusicVideo, LyricMusicVideo)
  
  lyrics                    = Template.ProxyContainer(Template.Proxy.Media, Template.Proxy.Remote, Template.Proxy.LocalFile)
  
  

class Artist(MetadataModel):
  model_name = 'Artist'

  title                     = Template.String()    
  title_sort                = Template.String()
  summary                   = Template.String()    
  countries                 = Template.Set(Template.String())
  posters                   = MediaProxyContainer()
  art                       = MediaProxyContainer()
  themes                    = MediaProxyContainer()

  extras                    = Template.ObjectContainer(MusicVideo, LiveMusicVideo, LyricMusicVideo, Interview, BehindTheScenes, ConcertVideo)

  similar                   = Template.Set(Template.String())
  concerts                  = Template.Set(Concert())

  # Interface settings
  
  xml_tag                   = 'Directory'
  xml_attributes            =  dict(type = 'artist')
  
  posters.exclude_from_interface
  art.exclude_from_interface
  themes.exclude_from_interface
  
  thumb                     = Template.String()
  thumb.is_synthetic

  genres                    = Template.Set(Template.String())
  genres.xml_tag            = 'Genre'

  moods                     = Template.Set(Template.String())
  moods.xml_tag             = 'Mood'

  styles                     = Template.Set(Template.String())
  styles.xml_tag             = 'Style'

  art_url                   = Template.String()
  art_url.is_synthetic
  art_url.synthetic_name    = 'art'
  
  track_count               = Template.Integer()
  track_count.is_synthetic
  track_count.xml_attr_name = 'leafCount'
  
  
  
class Album(object):
  model_name = 'Album'

  title                     = Template.String()
  title_sort                = Template.String()
  summary                   = Template.String()
  studio                    = Template.String()
  originally_available_at   = Template.Date()
  available_at              = Template.Date()
  producers                 = Template.Set(Person())
  countries                 = Template.Set(Template.String())  
  posters                   = MediaProxyContainer()
  art                       = MediaProxyContainer()
  tracks                    = Template.Map(Track())
  
  genres                    = Template.Set(Template.String())
  genres.xml_tag            = 'Genre'

  styles                     = Template.Set(Template.String())
  styles.xml_tag             = 'Style'

  moods                     = Template.Set(Template.String())
  moods.xml_tag             = 'Mood'

  album_format              = Template.Set(Template.String())
  album_type                = Template.Set(Template.String())

  # Interface settings.
  
  xml_tag                   = 'Directory'
  xml_attributes            =  dict(type = 'album')

  producers.xml_tag         = 'Producer'
  countries.xml_tag         = 'Country'
  
  posters.exclude_from_interface
  tracks.exclude_from_interface
  
  artist_name               = Template.String()
  artist_name.is_synthetic
  artist_name.xml_attr_name = 'parentTitle'
  artist_name.synthetic_name = 'artist'

  track_count               = Template.Integer()
  track_count.is_synthetic
  track_count.xml_attr_name = 'leafCount'
  
  thumb                     = Template.String()
  thumb.is_synthetic
  
  art_url                   = Template.String()
  art_url.is_synthetic
  art_url.synthetic_name    = 'art'


class LegacyAlbum(MetadataModel, Album):
  artist                    = Template.Link(Artist)
  artist.exclude_from_interface
  use_hashed_map_paths = True

class ModernAlbum(MetadataRecord, Album):
  pass

  
class LegacyArtist(Artist):
  albums = Template.Set(Template.Link(LegacyAlbum))


class ModernArtist(Artist):
  albums = Template.Map(ModernAlbum())
  albums.save_items_externally
  use_hashed_map_paths = True
