<?php

namespace Kylin\Auth\Enums;

use Kylin\Core\Contracts\KylinErrorCodeInterface;

/**
 * 认证错误码枚举
 *
 * 错误码格式：AUTH-{分类}-{编号}
 */
enum AuthErrorCode: string implements KylinErrorCodeInterface
{
    case LoginFailed = 'AUTH-LOGIN-001';
    case AccountDisabled = 'AUTH-LOGIN-002';
    case AccountLocked = 'AUTH-LOGIN-003';
    case TooManyAttempts = 'AUTH-LOGIN-004';
    case TokenExpired = 'AUTH-TOKEN-001';
    case TokenInvalid = 'AUTH-TOKEN-002';
    case CaptchaInvalid = 'AUTH-CAPTCHA-001';
    case PasswordExpired = 'AUTH-PWD-001';
    case RegisterDuplicateAccount = 'AUTH-REG-001';
    case RegisterFailed = 'AUTH-REG-002';

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

    public function message(): string
    {
        return match ($this) {
            self::LoginFailed => '账号或密码错误',
            self::AccountDisabled => '账号已被禁用',
            self::AccountLocked => '账号已被锁定',
            self::TooManyAttempts => '登录尝试次数过多，请稍后再试',
            self::TokenExpired => 'Token 已过期',
            self::TokenInvalid => 'Token 无效',
            self::CaptchaInvalid => '验证码错误或已过期',
            self::PasswordExpired => '密码已过期，请修改密码',
            self::RegisterDuplicateAccount => '该账号已被注册',
            self::RegisterFailed => '注册失败，请稍后重试',
        };
    }

    public function httpStatus(): int
    {
        return match ($this) {
            self::TokenExpired, self::TokenInvalid => 401,
            default => 400,
        };
    }
}
