<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;

class GameUser extends Model
{
    use HasFactory, SoftDeletes;

    protected $fillable = [
        'game_id',
        'user_id',
        'level',
        'type'
    ];

    protected $hidden = [
        'created_at',
        'updated_at',
        'deleted_at',
    ];

    public function user()
    {
        return $this->belongsTo(User::class,'user_id','id');
    }

    public function game_user_scores()
    {
        return $this->hasMany(GameUserScore::class, 'game_user_id', 'id');
    }

    public function addAll(array $data)
    {
        return $res = DB::table($this->getTable())->insert($data);
    }

}
