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

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 lombok.experimental.Accessors;
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
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
//hrsa_salary_sob_emp_field
@XStreamAlias("SalarySobEmpField")
public class SalarySobEmpFieldPO {

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

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

    /**
     * 字段code
     */
    @XStreamAlias("fieldCode")
    @XStreamAsAttribute
    private String fieldCode;

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

    /**
     * 是否可以删除
     */
    @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;

    Collection<Long> ids;

    public String toCompareString() {
        return "SalarySobEmpFieldPO{" +
                "salarySobId=" + salarySobId +
                ", fieldCode='" + fieldCode + '\'' +
                ", sortedIndex=" + sortedIndex +
                ", canDelete=" + canDelete +
                '}';
    }

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