package cn.superdesk.uniorder.dto.param.invoice.common;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.superdesk.uniorder.common.enums.common.CommonEnabledEnum;
import cn.superdesk.uniorder.common.pagination.AnBaseQueryCriteria;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.SuperBuilder;

/**
 * @Description: Java类作用描述
 * @Author: linjinyu
 * @CreateDate: 2022/2/11 下午3:51
 * @UpdateUser: linjinyu
 * @UpdateDate: 2022/2/11 下午3:51
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Data
@SuperBuilder(toBuilder = true)
public class InvoiceTypeQueryCriteria extends AnBaseQueryCriteria {

    @ApiModelProperty("是否启用:0-禁用;1-启用")
    private Integer enabled;
    @ApiModelProperty("是否强行突破是否启用限制:0-不;1-强行突破")
    private Integer breakthroughEnabled;

    @ApiModelProperty("是否默认:0-正常;1-默认;")
    private Integer isDefault;

    @ApiModelProperty("软删除:0-正常;1-删除;默认为0-正常")
    private Integer deleted = 0;

    @ApiModelProperty("[red]*[/red] 客户结算(customerGoods)|积分结算(customerCredit)|供应商结算(supplierGoods)")
    private String selectByModule;
    @ApiModelProperty("只读")
    private String queryCriteriaModule;

    @ApiModelProperty("排序,默认为 {selectByModule}_is_default desc, id asc sql -> order by {Module}_is_default desc, id asc")
    private String orderByExample = "{}_is_default desc, id asc";
//	@ApiModelProperty("只读")
//	private String orderBy;

    public InvoiceTypeQueryCriteria loading() {

        // 默认的情况下 只返回 启用的
        if (ObjectUtil.isNull(breakthroughEnabled) || ObjectUtil.isNull(enabled)) {
            enabled = CommonEnabledEnum.启用.getKey();
        }

        if (ObjectUtil.isNotNull(breakthroughEnabled)) {

            // 强行突破启用限制的情况
            if (breakthroughEnabled.compareTo(CommonEnabledEnum.启用.getKey()) == 0) {
                enabled = null;
            }

        }

        this.queryCriteriaModule = StrUtil.toUnderlineCase(this.selectByModule);
//		this.orderByClause = StrUtil.format(this.orderByExample, queryCriteriaModule);

        return this;
    }

}
