<?php

namespace Kylin\AntiAddiction\Enums;

use Kylin\Core\Contracts\KylinErrorCodeInterface;

/**
 * 防沉迷错误码枚举
 *
 * 错误码格式：ANTI-{分类}-{编号}
 */
enum AntiAddictionErrorCode: string implements KylinErrorCodeInterface
{
    case UnverifiedUser = 'ANTI-AUTH-001';
    case MinorTimeRestricted = 'ANTI-TIME-001';
    case MinorDurationExceeded = 'ANTI-TIME-002';
    case CurfewRestricted = 'ANTI-TIME-003';
    case SpendingSingleExceeded = 'ANTI-PAY-001';
    case SpendingMonthlyExceeded = 'ANTI-PAY-002';
    case SpendingForbidden = 'ANTI-PAY-003';
    case RealNameVerifyFailed = 'ANTI-AUTH-002';
    case FaceVerifyFailed = 'ANTI-AUTH-003';
    case FaceVerifyRequired = 'ANTI-AUTH-004';
    case HeartbeatTimeout = 'ANTI-SESSION-001';
    case BehaviorAnomalyDetected = 'ANTI-BEHAVIOR-001';
    case HolidayNotFound = 'ANTI-HOLIDAY-001';

    public function value(): string
    {
        return $this->value;
    }

    public function message(): string
    {
        return match ($this) {
            self::UnverifiedUser => '根据《关于进一步严格管理 切实防止未成年人沉迷网络游戏的通知》，所有网络游戏用户必须使用真实有效身份信息进行账号注册和登录，未完成实名认证的用户不可使用游戏服务',
            self::MinorTimeRestricted => '根据国家新闻出版署规定，未成年人仅可在周五、周六、周日和法定节假日每日20时至21时使用游戏服务，每次时长不超过1小时',
            self::MinorDurationExceeded => '根据国家新闻出版署规定，您今日的游戏时长已达上限，请合理安排时间，健康游戏',
            self::CurfewRestricted => '当前为未成年人禁止游戏时段（每日22时至次日8时），请您休息',
            self::SpendingSingleExceeded => '根据《关于防止未成年人沉迷网络游戏的通知》，您的单次充值金额超出限额',
            self::SpendingMonthlyExceeded => '根据《关于防止未成年人沉迷网络游戏的通知》，您的本月累计充值金额超出限额',
            self::SpendingForbidden => '根据《关于防止未成年人沉迷网络游戏的通知》，未满8周岁的用户不得进行游戏付费服务',
            self::RealNameVerifyFailed => '实名认证失败，请检查姓名和身份证号是否正确',
            self::FaceVerifyFailed => '人脸验证失败，请重新验证',
            self::FaceVerifyRequired => '根据防沉迷规定，需要进行人脸识别验证以确认身份',
            self::HeartbeatTimeout => '连接超时，请重新登录',
            self::BehaviorAnomalyDetected => '检测到异常游戏行为，需要进行身份验证',
            self::HolidayNotFound => '未找到节假日数据',
        };
    }

    public function httpStatus(): int
    {
        return match ($this) {
            self::UnverifiedUser,
            self::RealNameVerifyFailed,
            self::FaceVerifyFailed,
            self::FaceVerifyRequired => 403,
            self::HolidayNotFound => 404,
            default => 400,
        };
    }
}
