<?php

declare(strict_types=1);

namespace App\GraphQL\Schema\Queries\Models\Pagination\List\Playlist;

use App\Contracts\GraphQL\Fields\DeprecatedField;
use App\GraphQL\Argument\Argument;
use App\GraphQL\Schema\Fields\List\Playlist\PlaylistTrack\PlaylistTrackPlaylistField;
use App\GraphQL\Schema\Queries\Models\Pagination\EloquentPaginationQuery;
use App\GraphQL\Schema\Types\List\Playlist\PlaylistTrackType;
use App\Models\List\Playlist;
use App\Models\List\Playlist\PlaylistTrack;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Arr;

class PlaylistTrackPaginationQuery extends EloquentPaginationQuery implements DeprecatedField
{
    public function name(): string
    {
        return 'playlisttrackPagination';
    }

    public function description(): string
    {
        return 'Returns a listing of tracks for the playlist.';
    }

    /**
     * The arguments of the type.
     *
     * @return Argument[]
     */
    public function arguments(): array
    {
        return [
            ...parent::arguments(),

            ...($this->resolveBindArguments([new PlaylistTrackPlaylistField()])),
        ];
    }

    /**
     * The base return type of the query.
     */
    public function baseType(): PlaylistTrackType
    {
        return new PlaylistTrackType();
    }

    protected function query(Builder $builder, array $args): Builder
    {
        /** @var Playlist $playlist */
        $playlist = Arr::get($args, 'playlist');

        $builder->where(PlaylistTrack::ATTRIBUTE_PLAYLIST, $playlist->getKey());

        return $builder;
    }

    public function deprecationReason(): string
    {
        return 'Internal use only. Use the playlistPagination.tracks relationship instead.';
    }
}
