<?php

namespace App\Transformers\Applications;

use App\Models\Applications\Conclusion;
use App\Transformers\Users\UserTransformer;
use League\Fractal\Resource\Item;
use League\Fractal\TransformerAbstract;

class ConclusionTransformer extends TransformerAbstract {
    protected array $defaultIncludes = [];

    protected array $availableIncludes = [
        'author', 'application'
    ];

    public function transform(Conclusion $model): array {
        return [
            'id' => $model->uuid,
            'message' => $model->message,
            'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null,
            'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : null
        ];
    }

    public function includeAuthor(Conclusion $model): ?Item {
        return $model->author ? $this->item($model->author, new UserTransformer()) : null;
    }

    public function includeApplication(Conclusion $model): ?Item {
        return $model->application ? $this->item($model->application, new ApplicationTransformer()) : null;
    }

}