package com.engine.salary.enums.salarysob;


import cn.hutool.core.util.ObjectUtil;
import com.engine.salary.enums.BaseEnum;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 人员状态
 * <p>Copyright: Copyright (c) 2022</p>
 * <p>Company: 泛微软件</p>
 *
 * @author qiantao
 * @version 1.0
 **/
public enum SalaryEmployeeStatusEnum implements BaseEnum<Integer> {

    TRIAL(0, "试用", 100121),

    FORMAL(1, "正式", 100122),

    TEMPORARY(2, "临时", 100123),

    DELAY(3, "试用延期", 100124),

    FIRE(4, "解雇", 100125),

    DEPARTURE(5, "离职", 100126),

    RETIRED(6, "退休", 100127),
    ;

    private int value;

    private String defaultLabel;

    private int labelId;

    SalaryEmployeeStatusEnum(int value, String defaultLabel, int labelId) {
        this.value = value;
        this.defaultLabel = defaultLabel;
        this.labelId = labelId;
    }

    @Override
    public Integer getValue() {
        return value;
    }

    @Override
    public Integer getLabelId() {
        return labelId;
    }

    @Override
    public String getDefaultLabel() {
        return defaultLabel;
    }

    public static SalaryEmployeeStatusEnum parseByValue(Integer value) {
        for (SalaryEmployeeStatusEnum statusEnum : SalaryEmployeeStatusEnum.values()) {
            if (Objects.equals(statusEnum.getValue(), value)) {
                return statusEnum;
            }
        }
        return null;
    }


    public static List<SalaryEmployeeStatusEnum> parseByValues(List<Integer> value) {
        ArrayList<SalaryEmployeeStatusEnum> results = new ArrayList<>();
        for (SalaryEmployeeStatusEnum statusEnum : SalaryEmployeeStatusEnum.values()) {
            for(Integer v : value){
                if(Objects.equals(statusEnum.getValue(),v)){
                    results.add(statusEnum);
                }
            }
        }
        return results;
    }

    /**
     * @description 获取所有人员状态的value值的list
     * @return List<String>
     * @author Harryxzy
     * @date 2023/1/9 14:34
     */
    public static List<String> getAllSalaryEmployeeStatusValues() {
        List<String> values = new ArrayList<>();
        for (SalaryEmployeeStatusEnum statusEnum : SalaryEmployeeStatusEnum.values()) {
            values.add(ObjectUtil.toString(statusEnum.getValue()));
        }
        return values;
    }


    /**
     * @description 根据string”、“间隔的格式，获取所有人员状态value集合
     * @return List<String>
     * @author Harryxzy
     * @date 2023/1/9 14:35
     */
    public static List<String> parseByFormatStr(String statusStr, Boolean[] haveError) {
        List<String> result = new ArrayList<>();
        String[] status = statusStr.split("、");
        Arrays.stream(status).forEach(s -> {

            String value = null;
            for (SalaryEmployeeStatusEnum statusEnum : SalaryEmployeeStatusEnum.values()) {
                if (Objects.equals(statusEnum.getDefaultLabel(), s)) {
                    value = ObjectUtil.toString(statusEnum.getValue());
                    break;
                }
            }
            if(value != null ){
                result.add(value);
            }else{
                haveError[0] = true;
                return;
            }
        });
        return result;
    }


    /**
     * @description 根据string”、“间隔的格式，获取所有人员状态枚举数组
     * @return List<String>
     * @author Harryxzy
     * @date 2023/1/9 14:35
     */
    public static SalaryEmployeeStatusEnum[] getEnumsParseByFormatStr(String statusStr, Boolean[] haveError) {
        List<SalaryEmployeeStatusEnum> result = new ArrayList<>();
        String[] status = statusStr.split("、");
        Arrays.stream(status).forEach(s -> {

            SalaryEmployeeStatusEnum value = null;
            for (SalaryEmployeeStatusEnum statusEnum : SalaryEmployeeStatusEnum.values()) {
                if (Objects.equals(statusEnum.getDefaultLabel(), s)) {
                    value =statusEnum;
                    break;
                }
            }
            if(value != null ){
                result.add(value);
            }else{
                haveError[0] = true;
                return;
            }
        });
        SalaryEmployeeStatusEnum[] array = new SalaryEmployeeStatusEnum[result.size()];
        result.toArray(array);
        return array;
    }

}
