<?php
declare(strict_types=1);
define('BASE_PATH', dirname(__DIR__));
require BASE_PATH . '/vendor/autoload.php';
\Dotenv\Dotenv::createUnsafeMutable(BASE_PATH)->load();
\Webman\Config::load(BASE_PATH . '/config', ['route', 'plugin']);
\Webman\ThinkOrm\ThinkOrm::start(null);

use app\dice\helper\AdminScopeHelper;
use app\dice\logic\reward_config\DiceRewardConfigLogic;
use plugin\saiadmin\app\cache\UserInfoCache;

$adminInfo = UserInfoCache::getUserInfo(123);
$logic = new DiceRewardConfigLogic();

// paginated default
$query = $logic->search([]);
AdminScopeHelper::applyConfigScope($query, $adminInfo, 0);
$page = $logic->getList($query);
echo "default paginate count=" . count($page['data'] ?? []) . " total=" . ($page['total'] ?? 0) . "\n";

// saiType all
$_GET['saiType'] = 'all';
$_REQUEST['saiType'] = 'all';
$query2 = $logic->search([]);
AdminScopeHelper::applyConfigScope($query2, $adminInfo, 0);
$all = $logic->getList($query2);
echo "saiType=all is_array=" . (is_array($all) ? 'yes' : 'no') . " count=" . (is_array($all) ? count($all) : 0) . "\n";

$nonBigwin = 0;
if (is_array($all)) {
    foreach ($all as $row) {
        if (($row['tier'] ?? '') !== 'BIGWIN') {
            $nonBigwin++;
        }
    }
}
echo "non-BIGWIN rows for index tab: {$nonBigwin}\n";

// simulate dept_id=1123 explicit
unset($_GET['saiType'], $_REQUEST['saiType']);
$_GET['saiType'] = 'all';
$query3 = $logic->search([]);
AdminScopeHelper::applyConfigScope($query3, $adminInfo, 1123);
$all3 = $logic->getList($query3);
echo "dept_id=1123 saiType=all count=" . (is_array($all3) ? count($all3) : 0) . "\n";
