package com.ningdatech.carapi.car.equipment.converter;

import java.util.Objects;

import com.ningdatech.carapi.car.equipment.model.NdVehicleEquipmentJoin;
import com.ningdatech.carapi.car.equipment.model.vo.VehicleEquipmentVO;
import com.ningdatech.carapi.car.vehicle.model.NdVehicleBaseInfoJoin;
import com.ningdatech.carapi.common.constant.CarStatusEnum;
import com.ningdatech.carapi.common.constant.VehicleTypeEnum;
import com.ningdatech.carapi.common.util.CodeUtil;

import cn.hutool.core.bean.BeanUtil;

/**
 * @Classname CompanyRegionConverter
 * @Description
 * @Date 2022/10/9 10:30
 * @Created by PoffyZhang
 */
public class VehicleEquipmentConverter {

    public static VehicleEquipmentVO convert(NdVehicleBaseInfoJoin vehicle) {
        if(Objects.isNull(vehicle) || Objects.isNull(vehicle.getId())){
            return null;
        }
        VehicleEquipmentVO res = BeanUtil.copyProperties(vehicle, VehicleEquipmentVO.class);
        CodeUtil.searchCompanyNameAndRegionName(res);
        res.setVehicleTypeName(VehicleTypeEnum.getDescByCode(res.getVehicleType()));
        res.setVehicleStatus(vehicle.getVehicleStatus());
        res.setVehicleStatusName(CarStatusEnum.getDescByCode(vehicle.getVehicleStatus()));
        res.setLastOnlineTime(vehicle.getLastOnlineTime());
        return res;
    }

    public static VehicleEquipmentVO convert(NdVehicleEquipmentJoin equipment) {
        if(Objects.isNull(equipment) || Objects.isNull(equipment.getId())){
            return null;
        }
        VehicleEquipmentVO res = BeanUtil.copyProperties(equipment, VehicleEquipmentVO.class);
        CodeUtil.searchCompanyNameAndRegionName(res);
        res.setId(equipment.getVehicleId());
        res.setEquipmentId(equipment.getId());
        res.setVehicleTypeName(VehicleTypeEnum.getDescByCode(res.getVehicleType()));
        return res;
    }
}
