<?php

namespace Kylin\GameData\Enums;

use Kylin\Core\Contracts\KylinErrorCodeInterface;

/**
 * 游戏数据错误码枚举
 */
enum GameDataErrorCode: string implements KylinErrorCodeInterface
{
    case SaveNotFound = 'GDATA-NOTFOUND-001';
    case SaveConflict = 'GDATA-BIZ-001';
    case SaveTooLarge = 'GDATA-BIZ-002';
    case SyncTooFrequent = 'GDATA-BIZ-003';
    case InvalidVersion = 'GDATA-BIZ-004';
    case ChecksumMismatch = 'GDATA-BIZ-005';
    case HistoryNotFound = 'GDATA-NOTFOUND-002';
    case GameNotFound = 'GDATA-NOTFOUND-003';

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

    public function message(): string
    {
        return match ($this) {
            self::SaveNotFound => '存档不存在',
            self::SaveConflict => '数据冲突，需要解决后重试',
            self::SaveTooLarge => '存档数据超出大小限制',
            self::SyncTooFrequent => '同步过于频繁，请稍后再试',
            self::InvalidVersion => '版本号无效',
            self::ChecksumMismatch => '数据校验和不匹配',
            self::HistoryNotFound => '存档历史不存在',
            self::GameNotFound => '游戏不存在',
        };
    }

    public function httpStatus(): int
    {
        return match ($this) {
            self::SaveNotFound, self::HistoryNotFound, self::GameNotFound => 404,
            self::SaveConflict => 409,
            self::SaveTooLarge => 413,
            self::SyncTooFrequent => 429,
            default => 400,
        };
    }
}
