package com.ruoyi.web.modules.trading.support;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.modules.trading.domain.BizIsolationSetting;

/**
 * 默认隔离天数配置校验。
 */
public final class IsolationSettingValidation
{
    private IsolationSettingValidation()
    {
    }

    public static void trimFieldsForSave(BizIsolationSetting row)
    {
        if (row == null)
        {
            return;
        }
        if (row.getRemark() != null)
        {
            String remark = row.getRemark().trim();
            row.setRemark(remark.isEmpty() ? null : remark);
        }
    }

    public static void validateDefaultDays(Integer defaultDays)
    {
        if (defaultDays == null)
        {
            throw new ServiceException("请填写默认隔离天数");
        }
        if (defaultDays < IsolationPenRules.MIN_DEFAULT_DAYS || defaultDays > IsolationPenRules.MAX_DEFAULT_DAYS)
        {
            throw new ServiceException("默认隔离天数须在1～3650天之间");
        }
    }

    public static void validateRemark(String remark)
    {
        if (remark != null && remark.length() > 50)
        {
            throw new ServiceException("配置备注不能超过50个字符");
        }
    }

    public static void validateRowForSave(BizIsolationSetting row)
    {
        if (row == null)
        {
            throw new ServiceException("配置不能为空");
        }
        trimFieldsForSave(row);
        validateDefaultDays(row.getDefaultDays());
        validateRemark(row.getRemark());
        row.setId(IsolationPenRules.SETTING_SINGLETON_ID);
    }
}
