package com.cyl.manager.staff.domain.vo;

import com.cyl.manager.staff.domain.Staff;
import com.ruoyi.common.exception.ServiceException;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;

/**
 * 保证金扣除FORM
 */
@Data
public class DeductBondSubmitForm {

    @NotNull
    private Long staffId;

    @ApiModelProperty("扣除保证金金额")
    @NotNull(message = "扣除金额不能为空")
    @Min(value = 1, message = "金额必须大于0")
    private BigDecimal amount;

    @NotEmpty(message = "扣除保证金备注不能为空")
    @ApiModelProperty("扣除保证金备注")
    private String remark;

    /**
     * 校验参数
     * @param staff
     * @param deductAmount
     */
    public void validParams(Staff staff, BigDecimal deductAmount) {

        if (deductAmount != null && deductAmount.compareTo(new BigDecimal(0)) <= 0) {
            throw new ServiceException("扣除保证金金额必须大于0!");
        }

        //校验扣除的保证金金额不能大于 员工剩余的保证金额度
        if (staff.getBondAmount() == null || staff.getBondAmount().compareTo(deductAmount) <= 0) {
            throw new ServiceException("扣除的保证金金额不能大于员工剩余的保证金额度!");
        }

    }

}