<?php

namespace App\Entities\Chat;

use App\Entities\Usuarios\UserEntity;
use App\Models\Chat\ChatMessageModel;
use App\Models\Usuarios\UserModel;
use CodeIgniter\Entity\Entity;
use CodeIgniter\HTTP\Message;

class ChatNotificationEntity extends Entity
{
    protected $attributes = [
        "id" => null,
        "chat_message_id" => null,
        "user_id" => null,
        "viewed" => null,
    ];


    protected $casts = [
        "chat_message_id" => "integer",
        "user_id" => "integer",
        "viewed" => "boolean",
    ];

    public function message() : ?ChatMessageEntity
    {
        $m = model(ChatMessageModel::class);
        return $m->find($this->attributes['chat_message_id']);
    }
    public function user() : ?UserEntity
    {
        $m = model(UserModel::class);
        return $m->find($this->attributes['user_id']);
    }
    public function chat() : ?ChatEntity
    {
        return $this->message()->chat();
    }

}
