package com.engine.salary.entity.salarysob.po;

import com.engine.hrmelog.annotation.ElogTransform;
import com.engine.salary.entity.salaryformula.po.FormulaPO;
import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
import com.engine.salary.enums.SalaryRoundingModeEnum;
import com.engine.salary.enums.SalaryValueTypeEnum;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 薪资账套薪资项目
 * <p>Copyright: Copyright (c) 2022</p>
 * <p>Company: 泛微软件</p>
 *
 * @author qiantao
 * @version 1.0
 **/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
//hrsa_salary_sob_item
@ElogTransform( name="薪资账套薪资项目" )
@XStreamAlias("SalarySobItem")
public class SalarySobItemPO {

    /**
     * 主键id
     */
    @XStreamAlias("id")
    @XStreamAsAttribute
    private Long id;

    /**
     * 薪资账套的id
     */
    @XStreamAlias("salarySobId")
    @XStreamAsAttribute
    private Long salarySobId;

    /**
     * 薪资项目的id
     */
    @XStreamAlias("salaryItemId")
    @XStreamAsAttribute
    private Long salaryItemId;

    /**
     * 薪资账套薪资项目分组id
     */
    @XStreamAlias("salarySobItemGroupId")
    @XStreamAsAttribute
    private Long salarySobItemGroupId;

    /**
     * 公式
     */
    @XStreamAlias("formulaId")
    @XStreamAsAttribute
    private Long formulaId;

    /**
     * 排序字段
     */
    @XStreamAlias("sortedIndex")
    @XStreamAsAttribute
    private Integer sortedIndex;

    /**
     * 备注
     */
    @XStreamAlias("description")
    @XStreamAsAttribute
    private String description;


    /**
     * 进位规则
     *
     * @see SalaryRoundingModeEnum
     */
    @XStreamAlias("roundingMode")
    @XStreamAsAttribute
    private Integer roundingMode;

    /**
     * 保留的小数位数
     */
    @XStreamAlias("pattern")
    @XStreamAsAttribute
    private Integer pattern;

    /**
     * 取值方式
     *
     * @see SalaryValueTypeEnum
     */
    @XStreamAlias("valueType")
    @XStreamAsAttribute
    private Integer valueType;


    //该分类是否隐藏（0不隐藏，1隐藏）
    @XStreamAlias("itemHide")
    @XStreamAsAttribute
    private Long itemHide;

    /**
     * 默认值
     */
    @XStreamAlias("defaultValue")
    @XStreamAsAttribute
    private String defaultValue;

    /**
     * 是否可以删除。0：不可删除、1：可以删除
     */
    @XStreamAlias("canDelete")
    @XStreamAsAttribute
    private Integer canDelete;

    /**
     * 租户key
     */
    @XStreamAlias("tenantKey")
    @XStreamAsAttribute
    private String tenantKey;

    /**
     * 创建人id
     */
    @XStreamAlias("creator")
    @XStreamAsAttribute
    private Long creator;

    /**
     * 是否删除
     */
    @XStreamAlias("deleteType")
    @XStreamAsAttribute
    private Integer deleteType;

    /**
     * 创建时间
     */
    @XStreamAlias("createTime")
    @XStreamAsAttribute
    private Date createTime;

    /**
     * 更新时间
     */
    @XStreamAlias("updateTime")
    @XStreamAsAttribute
    private Date updateTime;

    @XStreamAlias("SalaryItem")
    private SalaryItemPO salaryItem;

    @XStreamAlias("Formula")
    private FormulaPO formula;

    //in
    Collection<Long> ids;
    Collection<Long> salarySobIds;


    Collection<Long> salaryItemIds;

    Collection<Long> notInSalaryItemIds;


    public String toCompareString() {
        return "SalarySobItemPO{" +
                "salarySobId=" + salarySobId +
                ", salaryItemId=" + salaryItemId +
                ", salarySobItemGroupId=" + salarySobItemGroupId +
                ", formulaId=" + formulaId +
                ", sortedIndex=" + sortedIndex +
                ", canDelete=" + canDelete +
                ", roundingMode=" + roundingMode +
                ", pattern=" + pattern +
                ", valueType=" + valueType +
                ", itemHide=" + itemHide +
                ", defaultValue=" + defaultValue +
                '}';
    }

    public static String toCompareString(List<SalarySobItemPO> salarySobItems) {
        if (CollectionUtils.isEmpty(salarySobItems)) {
            return "";
        }
        return salarySobItems.stream()
                .sorted(Comparator.comparingLong(SalarySobItemPO::getSalaryItemId))
                .map(SalarySobItemPO::toCompareString)
                .collect(Collectors.joining(","));
    }

}
