package com.yuchen.saas.parking.api.enums;

import com.thinkunion.park.service.common.constant.ParkingConstant;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.nest.springwrap.core.tool.utils.Func;

/**
 *  车牌类型（0：标准民用车，1：02式民用车牌，2：武警车车牌，3：警车车牌，4：民用车双行尾牌，5：使馆车牌，6：农用车车牌，7：摩托车，8：新能源车，13：军车车牌）费
 * @author CXJ
 */
@AllArgsConstructor
@Getter
public enum PlateTypeEnum {


    STANDARD_CIVILIAN_CAR(0, ParkingConstant.SpecialPlate.STANDARD_CIVILIAN_CAR),
    TYPE_02_CIVIL_LICENSE_PLATE(1, ParkingConstant.SpecialPlate.TYPE_02_CIVIL_LICENSE_PLATE),
    ARMED_POLICE_VEHICLE_LICENSE_PLATE(2, ParkingConstant.SpecialPlate.ARMED_POLICE_VEHICLE_LICENSE_PLATE),
    THE_POLICE_CAR_LICENSE_PLATE(3, ParkingConstant.SpecialPlate.THE_POLICE_CAR_LICENSE_PLATE),
    CIVIL_CAR_DOUBLE_ROW_TAIL_PLATE(4, ParkingConstant.SpecialPlate.CIVIL_CAR_DOUBLE_ROW_TAIL_PLATE),
    THE_EMBASSY_OF_THE_LICENSE_PLATE(5, ParkingConstant.SpecialPlate.THE_EMBASSY_OF_THE_LICENSE_PLATE),
    LICENSE_PLATE_OF_AGRICULTURAL_VEHICLE(6, ParkingConstant.SpecialPlate.LICENSE_PLATE_OF_AGRICULTURAL_VEHICLE),
    MOTORBIKE(7, ParkingConstant.SpecialPlate.MOTORBIKE),
    NEW_ENEGRY_VEHICLE(8, ParkingConstant.SpecialPlate.NEW_ENEGRY_VEHICLE),
    MILITARY_VEHICLES_LICENSE_PLATE(13, ParkingConstant.SpecialPlate.MILITARY_VEHICLES_LICENSE_PLATE),
    ;

    private Integer code;

    private String desc;

    public static String getDescByCode(Integer code) {
        PlateTypeEnum[] enumArray = PlateTypeEnum.values();
        for (PlateTypeEnum e : enumArray) {
            if (e.getCode().equals(code)) {
                return e.getDesc();
            }
        }
        return "";
    }

    public static Integer getCodeByDesc(String desc) {
        if(Func.isEmpty(desc)){
            return null;
        }
        PlateTypeEnum[] enumArray = PlateTypeEnum.values();
        for (PlateTypeEnum e : enumArray) {
            if (e.getDesc().equals(desc.replaceAll("\\s*", ""))) {
                return e.getCode();
            }
        }
        return null;
    }
}
