<?php

namespace App\Transformers\Chats;

use App\Models\Chats\Chat;
use App\Transformers\Users\UserTransformer;
use League\Fractal\Resource\Collection;
use League\Fractal\Resource\Item;
use League\Fractal\TransformerAbstract;

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

    protected array $availableIncludes = [
        'manager', 'client', 'messages'
    ];

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

    public function includeManager(Chat $model): ?Item {
        return $model->manager ? $this->item($model->manager, new UserTransformer()) : null;
    }

    public function includeClient(Chat $model): ?Item {
        return $model->client ? $this->item($model->client, new ClientTransformer()) : null;
    }

    public function includeMessages(Chat $model): Collection {
        return $this->collection($model->messages, new MessageTransformer());
    }


}