<commit_before><?php

namespace App\Transformers\Outbound\Collections;

use App\Transformers\Outbound\Collections\Artwork as ArtworkTransformer;
use App\Transformers\Outbound\Collections\Agent as AgentTransformer;
use App\Transformers\Outbound\CollectionsTransformer;

use App\Transformers\Outbound\Collections\Traits\HidesDefaultFields;

use App\Transformers\Outbound\CollectionsTransformer as BaseTransformer;

class ArtworkArtistPivot extends BaseTransformer
{
    use HidesDefaultFields;

    /**
     * List of resources possible to include
     *
     * @var array
     */
    protected $availableIncludes = [
        'artist',
        'artwork',
        'role',
    ];

    /**
     * Include artist.
     *
     * @param  \App\Models\Collections\ArtworkArtistPivot  $pivot
     * @return \League\Fractal\Resource\Item
     */
    public function includeArtist($pivot)
    {
        return $this->item($pivot->artist, new AgentTransformer(), false);
    }

    /**
     * Include artwork.
     *
     * @param  \App\Models\Collections\ArtworkArtistPivot  $pivot
     * @return \League\Fractal\Resource\Item
     */
    public function includeArtwork($pivot)
    {
        return $this->item($pivot->artwork, new ArtworkTransformer(), false);
    }

    /**
     * Include agent role.
     *
     * @param  \App\Models\Collections\ArtworkArtistPivot  $pivot
     * @return \League\Fractal\Resource\Item
     */
    public function includeRole($pivot)
    {
        return $this->item($pivot->role, new CollectionsTransformer(), false);
    }

    protected function getFields()
    {
        return [
            // TODO: Rename to `is_preferred`
            'preferred' => [
                'doc' => 'Whether this is a preferred artist',
                'type' => 'boolean',
            ],
            'artist_title' => [
                'doc' => 'Name of the artist',
                'type' => 'string',
                'value' => function ($item) {
                    return $item->artist->title ?? null;
                },
            ],
            'artist_id' => [
                'doc' => 'Unique identifier of the artist',
                'type' => 'number',
                'value' => function ($item) {
                    return $item->artist->citi_id ?? null;
                },
            ],
            'role_title' => [
                'doc' => 'Name of the role this artist played in the making of the work',
                'type' => 'string',
                'value' => function ($item) {
                    return $item->role->title ?? null;
                },
            ],
            'role_id' => [
                'doc' => 'Unique identifier of the role this artist played in the making of the work',
                'type' => 'number',
                'value' => function ($item) {
                    return $item->role->citi_id ?? null;
                },
            ],
        ];
    }

}<commit_msg>On ArtworkArtist pivot, don't query full object when all we need is an ID [WEB-1292]<commit_after><?php

namespace App\Transformers\Outbound\Collections;

use App\Transformers\Outbound\Collections\Artwork as ArtworkTransformer;
use App\Transformers\Outbound\Collections\Agent as AgentTransformer;
use App\Transformers\Outbound\CollectionsTransformer;

use App\Transformers\Outbound\Collections\Traits\HidesDefaultFields;

use App\Transformers\Outbound\CollectionsTransformer as BaseTransformer;

class ArtworkArtistPivot extends BaseTransformer
{
    use HidesDefaultFields;

    /**
     * List of resources possible to include
     *
     * @var array
     */
    protected $availableIncludes = [
        'artist',
        'artwork',
        'role',
    ];

    /**
     * Include artist.
     *
     * @param  \App\Models\Collections\ArtworkArtistPivot  $pivot
     * @return \League\Fractal\Resource\Item
     */
    public function includeArtist($pivot)
    {
        return $this->item($pivot->artist, new AgentTransformer(), false);
    }

    /**
     * Include artwork.
     *
     * @param  \App\Models\Collections\ArtworkArtistPivot  $pivot
     * @return \League\Fractal\Resource\Item
     */
    public function includeArtwork($pivot)
    {
        return $this->item($pivot->artwork, new ArtworkTransformer(), false);
    }

    /**
     * Include agent role.
     *
     * @param  \App\Models\Collections\ArtworkArtistPivot  $pivot
     * @return \League\Fractal\Resource\Item
     */
    public function includeRole($pivot)
    {
        return $this->item($pivot->role, new CollectionsTransformer(), false);
    }

    protected function getFields()
    {
        return [
            // TODO: Rename to `is_preferred`
            'preferred' => [
                'doc' => 'Whether this is a preferred artist',
                'type' => 'boolean',
            ],
            'artist_title' => [
                'doc' => 'Name of the artist',
                'type' => 'string',
                'value' => function ($item) {
                    return $item->artist->title ?? null;
                },
            ],
            'artist_id' => [
                'doc' => 'Unique identifier of the artist',
                'type' => 'number',
                'value' => function ($item) {
                    return $item->agent_citi_id ?? null;
                },
            ],
            'role_title' => [
                'doc' => 'Name of the role this artist played in the making of the work',
                'type' => 'string',
                'value' => function ($item) {
                    return $item->role->title ?? null;
                },
            ],
            'role_id' => [
                'doc' => 'Unique identifier of the role this artist played in the making of the work',
                'type' => 'number',
                'value' => function ($item) {
                    return $item->agent_role_citi_id ?? null;
                },
            ],
        ];
    }

}
{'fraction_non_alphanumeric': 0.12285714285714286, 'fraction_numerical': 0.0006722689075630252, 'mean_word_length': 1.7323232323232323, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 67, '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': '13155', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1628, 'n_words': 370}