<?php

declare(strict_types=1);

namespace App\Http\Api\Schema\Pivot\Wiki;

use App\Http\Api\Field\Base\CreatedAtField;
use App\Http\Api\Field\Base\UpdatedAtField;
use App\Http\Api\Field\Field;
use App\Http\Api\Field\Pivot\Wiki\AnimeStudio\AnimeStudioAnimeIdField;
use App\Http\Api\Field\Pivot\Wiki\AnimeStudio\AnimeStudioStudioIdField;
use App\Http\Api\Include\AllowedInclude;
use App\Http\Api\Schema\EloquentSchema;
use App\Http\Api\Schema\Wiki\AnimeSchema;
use App\Http\Api\Schema\Wiki\StudioSchema;
use App\Http\Resources\Pivot\Wiki\Resource\AnimeStudioJsonResource;
use App\Pivots\Wiki\AnimeStudio;

class AnimeStudioSchema extends EloquentSchema
{
    public function type(): string
    {
        return AnimeStudioJsonResource::$wrap;
    }

    /**
     * @return AllowedInclude[]
     */
    public function allowedIncludes(): array
    {
        return $this->withIntermediatePaths([
            new AllowedInclude(new AnimeSchema(), AnimeStudio::RELATION_ANIME),
            new AllowedInclude(new StudioSchema(), AnimeStudio::RELATION_STUDIO),
        ]);
    }

    /**
     * @return Field[]
     *
     * @noinspection PhpMissingParentCallCommonInspection
     */
    public function fields(): array
    {
        return [
            new CreatedAtField($this),
            new UpdatedAtField($this),
            new AnimeStudioAnimeIdField($this),
            new AnimeStudioStudioIdField($this),
        ];
    }
}
