<?php

namespace App\Support;

/**
 * user_login.platform 规范值 → 后台统计 bucket
 *
 * 写入侧（melbet）负责一次写对：
 * - iOS / Android = 原生 APP
 * - H5 = 手机 H5
 * - PC = 电脑
 * - WeChat = 微信（统计并入 mobile）
 *
 * 读侧只做映射，不再用 login_domain 二次推断。
 */
final class LoginPlatform
{
    public const BUCKET_APPLE = 'apple';
    public const BUCKET_ANDROID = 'android';
    public const BUCKET_PC = 'pc';
    public const BUCKET_MOBILE = 'mobile';
    public const BUCKET_UNKNOWN = 'unknown';

    /**
     * @return self::BUCKET_*
     */
    public static function toBucket(string $platform): string
    {
        $p = strtolower(trim($platform));
        return match ($p) {
            'ios', 'apple', '苹果' => self::BUCKET_APPLE,
            'android', '安卓' => self::BUCKET_ANDROID,
            'pc', 'windows', 'mac', 'macos', 'linux', 'chrome os', 'chromeos' => self::BUCKET_PC,
            'h5', 'mobile', '移动', 'wechat', '微信' => self::BUCKET_MOBILE,
            default => self::BUCKET_UNKNOWN,
        };
    }

    /**
     * 空计数骨架
     *
     * @return array{total:int,apple:int,android:int,pc:int,mobile:int,wechat:int,unknown:int}
     */
    public static function emptyCounts(): array
    {
        return [
            'total' => 0,
            'apple' => 0,
            'android' => 0,
            'pc' => 0,
            'mobile' => 0,
            'wechat' => 0,
            'unknown' => 0,
        ];
    }
}
