<?php

namespace App\Transformers\Chats;

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

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

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

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

    public function includeChat(Message $model): ?Item {
        return $model->chat ? $this->item($model->chat, new ChatTransformer()) : null;
    }

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

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


}