<?php

namespace App\Models;

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

class Game_list extends Model
{
    protected $table = 'game_baru';
    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'game_code',
        'game_provider',
        'game_name',
        'game_image',
        'category',

    ];    


    function get_game_list( $provider, $type){
        return $this->select('game_list.*', DB::RAW('IFNULL(game_locks.status, game_list.game_locked) as game_locks'))
            ->where([
                'category' => $type,
                'game_provider' => $provider,
                'game_list.status' => 1
            ])->leftJoin('game_locks', function($join){
                $user_id = empty(Auth()->user()) ? 0 : Auth()->user()->id;
                $join->on('game_list.id', '=', 'game_locks.game_id')
                ->where('game_locks.user_id', '=', $user_id)
                ->where('game_locks.status', '=', 1);
            })->get();
    }
}
