import { Injectable, type PipeTransform, UnprocessableEntityException } from '@nestjs/common';

@Injectable()
export class NonEmptyStringPipe implements PipeTransform<string, string> {
  /**
   * 静态 transform 方法 (用于装饰器)
   * @param value - 待验证的值
   */
  public transform(value: unknown): string {
    if (typeof value !== 'string' || value.trim().length === 0) {
      throw new UnprocessableEntityException('参数不能为空');
    }
    return value.trim();
  }
}
