<?php

namespace Kylin\Licensing\Enums;

use Kylin\Core\Contracts\KylinErrorCodeInterface;

/**
 * 许可错误码
 */
enum LicensingErrorCode: string implements KylinErrorCodeInterface
{
    case LicenseNotFound = 'LCS-NOTFOUND-001';
    case LicenseExpired = 'LCS-BIZ-001';
    case LicenseInvalid = 'LCS-BIZ-002';
    case LicenseDomainMismatch = 'LCS-BIZ-003';
    case LicenseIpMismatch = 'LCS-BIZ-004';
    case LicensePackageUnauthorized = 'LCS-PERM-001';
    case LicenseDeviceLimit = 'LCS-BIZ-005';
    case LicenseSuspended = 'LCS-BIZ-006';
    case LicenseRevoked = 'LCS-BIZ-007';
    case LicenseGracePeriod = 'LCS-BIZ-008';

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

    public function message(): string
    {
        return match ($this) {
            self::LicenseNotFound => '许可证不存在',
            self::LicenseExpired => '许可证已过期',
            self::LicenseInvalid => '许可证无效',
            self::LicenseDomainMismatch => '域名不在授权范围',
            self::LicenseIpMismatch => 'IP 不在授权范围',
            self::LicensePackageUnauthorized => '功能模块未授权',
            self::LicenseDeviceLimit => '设备数超限',
            self::LicenseSuspended => '许可证已被暂停',
            self::LicenseRevoked => '许可证已被吊销',
            self::LicenseGracePeriod => '许可证宽限期',
        };
    }

    public function httpStatus(): int
    {
        return match ($this) {
            self::LicenseGracePeriod => 200,
            default => 403,
        };
    }
}
