package com.sckw.usual.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/*
履约计费方式
 */
@AllArgsConstructor
@Getter
public enum PerChargingMode {

    SHIPPING_ACCOUNT(1, "按装货量结算"),
    LANDING_SETTLEMENT(2, "按卸货量结算"),
    BILLING_PER_TRIP(3,"按趟次结算"),
    TRANSPORTATION_MILES(4, "按运输里程计算");

    private final Integer code;
    private final String msg;


    public static String getNameByCode(Integer code) {
        PerChargingMode[] enums = PerChargingMode.values();
        for (PerChargingMode instance : enums) {
            if (Objects.equals(instance.getCode(), code)) {
                return instance.getMsg();
            }
        }
        return null;
    }

    public static List<PerChargingMode> getSortList() {
        PerChargingMode[] enums = PerChargingMode.values();
        return Arrays.stream(enums).sorted(Comparator.comparingInt(PerChargingMode::getCode)).collect(Collectors.toList());
    }
}
