import { defaults } from 'lodash';
import cached from '../fields/cached';
import initials from '../fields/initials';
import Image from '../image';
import Artwork from '../artwork';
import PartnerShow from '../partner_show';
import ArtworkSorts from '../sorts/artwork_sorts';
import PartnerShowSorts from '../sorts/partner_show_sorts';
import ArtistCarousel from './carousel';
import ArtistStatuses from './statuses';
import gravity from '../../lib/loaders/gravity';
import {
  GraphQLObjectType,
  GraphQLBoolean,
  GraphQLString,
  GraphQLNonNull,
  GraphQLList,
  GraphQLInt,
} from 'graphql';

const ArtistType = new GraphQLObjectType({
  name: 'Artist',
  fields: () => {
    return {
      cached,
      id: {
        type: GraphQLString,
      },
      href: {
        type: GraphQLString,
        resolve: (artist) => `/artist/${artist.id}`,
      },
      sortable_id: {
        type: GraphQLString,
        description: 'Use this attribute to sort by when sorting a collection of Artists',
      },
      name: {
        type: GraphQLString,
      },
      initials: initials('name'),
      years: {
        type: GraphQLString,
      },
      public: {
        type: GraphQLBoolean,
      },
      nationality: {
        type: GraphQLString,
      },
      is_shareable: {
        type: GraphQLBoolean,
        resolve: (artist) => artist.published_artworks_count > 0,
      },
      counts: {
        type: new GraphQLObjectType({
          name: 'counts',
          fields: {
            artworks: {
              type: GraphQLInt,
              resolve: ({ published_artworks_count }) => published_artworks_count,
            },
            follows: {
              type: GraphQLInt,
              resolve: ({ follow_count }) => follow_count,
            },
            auction_lots: {
              type: GraphQLInt,
              resolve: ({ auction_lots_count }) => auction_lots_count,
            },
          },
        }),
        resolve: (artist) => artist,
      },
      artworks: {
        type: new GraphQLList(Artwork.type),
        args: {
          size: {
            type: GraphQLInt,
            description: 'The number of Artworks to return',
          },
          sort: ArtworkSorts,
          published: {
            type: GraphQLBoolean,
            defaultValue: true,
          },
        },
        resolve: ({ id }, options) => gravity(`artist/${id}/artworks`, options),
      },
      image: Image,
      artists: {
        type: new GraphQLList(Artist.type), // eslint-disable-line no-use-before-define
        args: {
          size: {
            type: GraphQLInt,
            description: 'The number of Artists to return',
          },
          exclude_artists_without_artworks: {
            type: GraphQLBoolean,
            defaultValue: true,
          },
        },
        resolve: (artist, options) => {
          return gravity(`related/layer/main/artists`, defaults(options, {
            artist: [artist.id],
          }));
        },
      },

      carousel: ArtistCarousel,

      statuses: ArtistStatuses,

      partner_shows: {
        type: new GraphQLList(PartnerShow.type),
        args: {
          size: {
            type: GraphQLInt,
            description: 'The number of PartnerShows to return',
          },
          solo_show: {
            type: GraphQLBoolean,
          },
          top_tier: {
            type: GraphQLBoolean,
          },
          sort: PartnerShowSorts,
        },
        resolve: ({ id }, options) => {
          return gravity('related/shows', defaults(options, {
            artist_id: id,
            displayable: true,
            sort: '-end_at',
          }));
        },
      },
    };
  },
});

const Artist = {
  type: ArtistType,
  description: 'An Artist',
  args: {
    id: {
      description: 'The slug or ID of the Artist',
      type: new GraphQLNonNull(GraphQLString),
    },
  },
  resolve: (root, { id }) => gravity(`artist/${id}`),
};

export default Artist;

@@ -106,24 +106,67 @@
 /initials';%0A
+import markdown from '../fields/markdown';%0A
 import Image
@@ -1293,24 +1293,49 @@
 g,%0A      %7D,%0A
+      blurb: markdown(),%0A
       is_sha

Include artist blurbs