<?php

namespace App\Support;

use App\Models\AdminUser;

/** 期号 API 响应字段按「开奖查看 / 管理 / 资金」权限裁剪。 */
final class AdminDrawResponsePolicy
{
    public static function canManageDrawResults(AdminUser $admin): bool
    {
        return $admin->hasAdminPermission('prd.draw_result.manage');
    }

    public static function canViewDrawFinance(AdminUser $admin): bool
    {
        if (self::canManageDrawResults($admin)) {
            return true;
        }

        foreach ([
            'prd.payout.view',
            'prd.payout.manage',
            'prd.payout.review',
            'prd.report.view',
            'prd.users.view_finance',
        ] as $slug) {
            if ($admin->hasAdminPermission($slug)) {
                return true;
            }
        }

        return false;
    }

    /** @return array{can_manage_draw_results: bool, can_view_draw_finance: bool} */
    public static function capabilities(AdminUser $admin): array
    {
        return [
            'can_manage_draw_results' => self::canManageDrawResults($admin),
            'can_view_draw_finance' => self::canViewDrawFinance($admin),
        ];
    }
}
