# -*- coding: utf-8 -*-
"""数据验证器"""
from decimal import Decimal

class DataValidator:
    """数据验证工具"""
    
    @staticmethod
    def validate_positive_amount(value: Decimal | None, field_name: str = "amount"):
        """验证金额为正数"""
        if value is not None and value < 0:
            raise ValueError(f"{field_name} 不能为负数: {value}")
    
    @staticmethod
    def validate_required(value, field_name: str):
        """验证必填字段"""
        if value is None or value == "":
            raise ValueError(f"{field_name} 是必填字段")
    
    @staticmethod
    def validate_range(value, min_val, max_val, field_name: str):
        """验证值范围"""
        if value is not None:
            if value < min_val or value > max_val:
                raise ValueError(f"{field_name} 必须在 {min_val} 到 {max_val} 之间")
