<?php

namespace Kylin\WordFilter\Exceptions;

use Kylin\Core\Exceptions\KylinException;
use Kylin\WordFilter\Enums\WordFilterErrorCode;

/**
 * 敏感词过滤异常
 *
 * 统一封装敏感词过滤模块的错误，携带错误码和附加数据。
 */
class WordFilterException extends KylinException
{
    protected ?array $data = null;

    public static function fromCode(WordFilterErrorCode $errorCode, ?array $data = null): self
    {
        $instance = new self($errorCode);
        $instance->data = $data;

        return $instance;
    }

    public function getData(): ?array
    {
        return $this->data;
    }
}
