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

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.modules.booking.domain.AppMyAppointmentReviewBody;

/**
 * 提交预约评价校验。
 */
public final class AppMyAppointmentReviewValidation
{
    private static final int MIN_SCORE = 1;

    private static final int MAX_SCORE = 5;

    private static final int MAX_SUMMARY_LEN = 100;

    private AppMyAppointmentReviewValidation()
    {
    }

    public static void validate(AppMyAppointmentReviewBody body)
    {
        if (body == null)
        {
            throw new ServiceException("评价内容不能为空");
        }
        validateScore(body.getPunctualityScore(), "到场准时");
        validateScore(body.getAttitudeScore(), "服务态度");
        validateScore(body.getGuidanceScore(), "指导效果");
        if (StringUtils.isEmpty(body.getSummary()) || body.getSummary().trim().isEmpty())
        {
            throw new ServiceException("请填写综合评价");
        }
        String summary = body.getSummary().trim();
        if (summary.length() > MAX_SUMMARY_LEN)
        {
            throw new ServiceException("综合评价不能超过100字");
        }
        body.setSummary(summary);
    }

    private static void validateScore(Integer score, String label)
    {
        if (score == null || score < MIN_SCORE || score > MAX_SCORE)
        {
            throw new ServiceException(label + "请选择1-5星");
        }
    }
}
