<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\PwaBonusLog;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class PwaBonusLogController extends Controller
{
    public function index(Request $request)
    {
        $logDate = $request->input('log_date', '');
        $gameId = $request->input('game_id', '');
        $page = $request->input('page', 1);

        $query = DB::table(PwaBonusLog::TABLE);

        if (!empty($logDate)) {
            $query->where('log_date', $logDate);
        }

        if ($gameId !== '' && $gameId !== null) {
            $query->where('GameID', (int) $gameId);
        }

        $query->orderBy('created_at', 'desc');

        $list = $query->paginate(20, ['*'], 'page', $page);

        return view('admin.pwa_bonus_log.index', [
            'list' => $list,
            'log_date' => $logDate,
            'game_id' => $gameId,
        ]);
    }
}
