<?php

namespace Kylin\WordFilter\Enums;

use Kylin\Core\Contracts\KylinErrorCodeInterface;

enum WordFilterErrorCode: string implements KylinErrorCodeInterface
{
    case SensitiveWordBlocked = 'WF-FILTER-001';
    case SyncVersionExpired = 'WF-SYNC-001';
    case SyncVersionInvalid = 'WF-SYNC-002';
    case TrieBuildFailed = 'WF-ENGINE-001';
    case BatchSizeExceeded = 'WF-FILTER-002';
    case CategoryNotFound = 'WF-CATEGORY-001';

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

    public function message(): string
    {
        return match ($this) {
            self::SensitiveWordBlocked => '内容包含敏感词，已被拦截',
            self::SyncVersionExpired => '同步版本已过期，请使用最新版本号',
            self::SyncVersionInvalid => '无效的版本号',
            self::TrieBuildFailed => '敏感词引擎初始化失败',
            self::BatchSizeExceeded => '批量过滤数量超过限制',
            self::CategoryNotFound => '分类不存在',
        };
    }

    public function httpStatus(): int
    {
        return match ($this) {
            self::SensitiveWordBlocked => 403,
            self::BatchSizeExceeded => 422,
            default => 400,
        };
    }
}
