<?php

namespace App\Entities\Chat;

use App\Entities\Usuarios\UserEntity;
use App\Models\Chat\ChatModel;
use App\Models\Usuarios\UserModel;
use CodeIgniter\Entity\Entity;

class ChatUserEntity extends Entity
{
    protected $attributes = [
        "id" => null,
        "user_id" => null,
        "chat_id" => null,
    ];


    protected $casts = [
        "user_id" => "integer",
        "chat_id" => "integer",
    ];

    public function chat() : ?ChatEntity
    {
        $m = model(ChatModel::class);
        return $m->find($this->attributes['chat_id']);

    }
    public function user() : ?UserEntity
    {
        $m = model(UserModel::class);
        return $m->find($this->attributes['user_id'])->withAvatar();
    }

}
