package org.dromara.system.domain.bo;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.github.linpeilie.annotations.AutoMapper;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.DecimalMax;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.Digits;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.dromara.common.core.domain.model.BaseAudit;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import org.dromara.system.domain.CommissionSection;
import java.math.BigDecimal;

/**
 * 分成比例区间业务对象 commission_section
 * @author 86132
 */
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = CommissionSection.class, reverseConvertGenerate = false)
@Schema(name = "CommissionSectionBo", description = "分成比例区间业务对象")
public class CommissionSectionBo extends BaseAudit {
    /** 主键 */
    @Schema(description = "主键")
    private Integer id;

    /** 所属模板ID */
    @Schema(description = "所属模板ID")
    @NotNull(message = "所属模板ID不能为空")
    private Integer templateId;

    /** 区间下限（包含），单位：元 */
    @Schema(description = "区间下限（包含），单位：元")

    @Digits(integer = 17, fraction = 2, message = "区间下限最多19位，含2位小数")
    private BigDecimal minAmount;

    /** 区间上限（包含），单位：元 */
    @Schema(description = "区间上限（包含），单位：元")

    @Digits(integer = 17, fraction = 2, message = "区间上限最多19位，含2位小数")
    private BigDecimal maxAmount;

    /** 分成比例（如0.6000表示60%） */
    @Schema(description = "分成比例（如0.6000表示60%）")

    @Digits(integer = 1, fraction = 4, message = "分成比例最多5位，含4位小数")
    private BigDecimal rate;

    /** 区间名称 */
    @Schema(description = "名称")
    private String rateName;

    /**
     * 构建分页查询条件
     */
    public LambdaQueryWrapper<CommissionSection> toWrapper() {
        LambdaQueryWrapper<CommissionSection> wrapper = new LambdaQueryWrapper<>();
        if (this.getTemplateId() != null) {
            wrapper.eq(CommissionSection::getTemplateId, this.getTemplateId());
        }
        if (this.getMinAmount() != null) {
            wrapper.ge(CommissionSection::getMinAmount, this.getMinAmount());
        }
        if (this.getMaxAmount() != null) {
            wrapper.le(CommissionSection::getMaxAmount, this.getMaxAmount());
        }
        if (this.getRate() != null) {
            wrapper.eq(CommissionSection::getRate, this.getRate());
        }
        return wrapper;
    }
}
