<?php

namespace Kylin\Guardian\Enums;

use Kylin\Core\Contracts\KylinErrorCodeInterface;

/**
 * 监护人系统错误码枚举
 */
enum GuardianErrorCode: string implements KylinErrorCodeInterface
{
    case RegisterFailed = 'GRD-REG-001';
    case AlreadyRegistered = 'GRD-REG-002';
    case VerificationFailed = 'GRD-REG-003';
    case BindFailed = 'GRD-BIND-001';
    case BindingNotFound = 'GRD-BIND-002';
    case BindingAlreadyExists = 'GRD-BIND-003';
    case BindingDisabled = 'GRD-BIND-004';
    case GuardianNotFound = 'GRD-GUA-001';
    case MinorNotFound = 'GRD-GUA-002';
    case NotMinor = 'GRD-GUA-003';
    case InvalidRelationship = 'GRD-GUA-004';
    case PlayLimitExceeded = 'GRD-LMT-001';
    case SpendingLimitExceeded = 'GRD-LMT-002';
    case ForceOfflineFailed = 'GRD-CTL-001';
    case AllowOnlineFailed = 'GRD-CTL-002';
    case Unauthorized = 'GRD-PERM-001';

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

    public function message(): string
    {
        return match ($this) {
            self::RegisterFailed => '监护人注册失败',
            self::AlreadyRegistered => '该用户已注册为监护人',
            self::VerificationFailed => '监护人身份验证失败',
            self::BindFailed => '绑定未成年人失败',
            self::BindingNotFound => '绑定关系不存在',
            self::BindingAlreadyExists => '该未成年人已被当前监护人绑定',
            self::BindingDisabled => '绑定关系已禁用',
            self::GuardianNotFound => '监护人不存在',
            self::MinorNotFound => '未成年人用户不存在',
            self::NotMinor => '目标用户不是未成年人',
            self::InvalidRelationship => '无效的监护关系类型',
            self::PlayLimitExceeded => '游戏时长已超出限制',
            self::SpendingLimitExceeded => '消费金额已超出限制',
            self::ForceOfflineFailed => '强制下线操作失败',
            self::AllowOnlineFailed => '允许上线操作失败',
            self::Unauthorized => '无权操作此绑定关系',
        };
    }

    public function httpStatus(): int
    {
        return match ($this) {
            self::GuardianNotFound, self::BindingNotFound, self::MinorNotFound => 404,
            self::Unauthorized => 403,
            self::PlayLimitExceeded, self::SpendingLimitExceeded => 409,
            default => 400,
        };
    }
}
