<commit_before>_             = require 'underscore'
Backbone      = require 'backbone'
sd            = require('sharify').data
Artworks      = require '../collections/artworks.coffee'
{ Markdown }  = require 'artsy-backbone-mixins'
{ Image }     = require 'artsy-backbone-mixins'
{ smartTruncate }     = require '../components/util/string.coffee'
{ SECURE_IMAGES_URL } = require('sharify').data

module.exports = class Artist extends Backbone.Model

  _.extend @prototype, Markdown
  _.extend @prototype, Image(SECURE_IMAGES_URL)

  sortCriteriaForArtworks:
    ''               : 'Relevance'
    '-published_at'  : 'Recently Added'

  validSort: (sort) ->
    _.contains(_.keys(@sortCriteriaForArtworks), sort)

  urlRoot: -> "#{sd.ARTSY_URL}/api/v1/artist"

  clientUrl: -> "/artist/#{@get('id')}"
  href: -> "/artist/#{@get('id')}"

  initialize: ->
    @relatedArtists = new Backbone.Collection [], model: Artist
    @relatedArtists.url = "#{sd.ARTSY_URL}/api/v1/related/layer/main/artists"
    @relatedContemporary = new Backbone.Collection [], model: Artist
    @relatedContemporary.url = "#{sd.ARTSY_URL}/api/v1/related/layer/contemporary/artists"
    @relatedPosts = new Backbone.Collection [], model: require('./post.coffee')
    @relatedPosts.url = "#{sd.ARTSY_URL}/api/v1/related/posts"

  fetchRelatedArtists: (type, options = {}) ->
    @["related#{type}"].fetch _.extend
      remove: false
      data: _.extend (options.data ? {}),
        size: 5
        'artist[]': @get 'id'
        'exclude_artists_without_artworks': true
    , options

  fetchArtworks: (options) ->
    col = new Artworks
    col.url = "#{@url()}/artworks"
    col.fetch options

  fetchPosterArtwork: (options) ->
    @fetchArtworks
      data:
        page: 1
        size: 1
      success: (artworks) =>
        @set { poster_artwork: artworks.models[0] }
        @

  fetchRelatedPosts: (options = {}) ->
    @relatedPosts.fetch _.extend
      remove: false
      data: _.extend (options.data ? {}),
        size: 15
        'artist[]': @get 'id'
    , options

  toPageTitle: ->
    "#{if @get('name') then @htmlToText('name') else 'Unnamed Artist'} | Artist Bio and Art for Sale | Artsy"

  toPageDescription: (length=200) -><commit_msg>Set artworks as a property on initialize<commit_after>_             = require 'underscore'
Backbone      = require 'backbone'
sd            = require('sharify').data
Artworks      = require '../collections/artworks.coffee'
{ Markdown }  = require 'artsy-backbone-mixins'
{ Image }     = require 'artsy-backbone-mixins'
{ smartTruncate }     = require '../components/util/string.coffee'
{ SECURE_IMAGES_URL } = require('sharify').data

module.exports = class Artist extends Backbone.Model

  _.extend @prototype, Markdown
  _.extend @prototype, Image(SECURE_IMAGES_URL)

  sortCriteriaForArtworks:
    ''               : 'Relevance'
    '-published_at'  : 'Recently Added'

  validSort: (sort) ->
    _.contains(_.keys(@sortCriteriaForArtworks), sort)

  urlRoot: -> "#{sd.ARTSY_URL}/api/v1/artist"

  clientUrl: -> "/artist/#{@get('id')}"
  href: -> "/artist/#{@get('id')}"

  initialize: ->
    @relatedArtists = new Backbone.Collection [], model: Artist
    @relatedArtists.url = "#{sd.ARTSY_URL}/api/v1/related/layer/main/artists"
    @relatedContemporary = new Backbone.Collection [], model: Artist
    @relatedContemporary.url = "#{sd.ARTSY_URL}/api/v1/related/layer/contemporary/artists"
    @relatedPosts = new Backbone.Collection [], model: require('./post.coffee')
    @relatedPosts.url = "#{sd.ARTSY_URL}/api/v1/related/posts"
    @artworks = new Artworks
    @artworks.url = "#{@url()}/artworks"

  fetchArtworks: (options) ->
    @artworks.fetch options

  fetchRelatedArtists: (type, options = {}) ->
    @["related#{type}"].fetch _.extend
      remove: false
      data: _.extend (options.data ? {}),
        size: 5
        'artist[]': @get 'id'
        'exclude_artists_without_artworks': true
    , options

  fetchPosterArtwork: (options) ->
    @fetchArtworks
      data:
        page: 1
        size: 1
      success: (artworks) =>
        @set { poster_artwork: artworks.models[0] }
        @

  fetchRelatedPosts: (options = {}) ->
    @relatedPosts.fetch _.extend
      remove: false
      data: _.extend (options.data ? {}),
        size: 15
        'artist[]': @get 'id'
    , options

  toPageTitle: ->
    "#{if @get('name') then @htmlToText('name') else 'Unnamed Artist'} | Artist Bio and Art for Sale | Artsy"

  toPageDescription: (length=200) ->
{'fraction_non_alphanumeric': 0.15553583314843578, 'fraction_numerical': 0.005768804082538274, 'mean_word_length': 3.0, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2089560', 'n_tokens_mistral': 1514, 'n_tokens_neox': 1459, 'n_words': 290}