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

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
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_group
@XStreamAlias("SalarySobItemGroup")
public class SalarySobItemGroupPO {

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

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

    /**
     * 薪资账套中薪资项目分组的名称
     */
    @XStreamAlias("name")
    @XStreamAsAttribute
    private String name;

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

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


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

    /**
     * 租户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;

    @XStreamImplicit
    private List<SalarySobItemPO> salarySobItems;


    Collection<Long> ids;

    public String toCompareString() {
        return "SalarySobItemGroupPO{" +
                "name='" + name + '\'' +
                ", sortedIndex=" + sortedIndex +
                ", itemHide=" + itemHide +
                '}';
    }

    public static String toCompareString(List<SalarySobItemGroupPO> salarySobItemGroups) {
        if (CollectionUtils.isEmpty(salarySobItemGroups)) {
            return "";
        }
        return salarySobItemGroups.stream()
                .sorted(Comparator.comparing(SalarySobItemGroupPO::getSortedIndex))
                .map(SalarySobItemGroupPO::toCompareString)
                .collect(Collectors.joining(","));
    }
}
