<?php
namespace App\Models;

use App\Constants\Util;

class RoomUser extends BaseModel
{
    protected $table = 'room_users';
    protected $fillable = ['room_id', 'member_id', 'game_id', 'status', 'score', 'screenshot', 'game_id', 'first_name'];


    public function room()
    {
        return $this->belongsTo(Room::class, 'room_id', 'room_id');
    }

    protected function getBrokerageAttribute($value)
    {
        return floatval($value);
    }

    protected function getScoreAttribute($value)
    {
        return floatval($value);
    }

    protected function getRealScoreAttribute($value)
    {
        return floatval($value);
    }

    protected function getScreenshotAttribute($value)
    {
        return Util::ensureUrl($value);
    }

    protected function setScreenshotAttribute($value)
    {
        $this->attributes['screenshot'] = Util::replacePartInUrl($value);
    }
}
