package cn.iocoder.yudao.module.asset.convert.vehicle;

import cn.iocoder.yudao.module.asset.controller.admin.vehicle.vo.VehicleRespVO;
import cn.iocoder.yudao.module.asset.controller.admin.vehicle.vo.VehicleSimpleRespVO;
import cn.iocoder.yudao.module.asset.dal.dataobject.vehicle.VehicleBaseDO;
import cn.iocoder.yudao.module.asset.dal.dataobject.vehicle.VehicleBusinessDO;
import cn.iocoder.yudao.module.asset.dal.dataobject.vehicle.VehicleLocationDO;
import cn.iocoder.yudao.module.asset.dal.dataobject.vehicle.VehicleStatusDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 车辆 Convert
 *
 * @author 芋道源码
 */
@Mapper
public interface VehicleConvert {

    VehicleConvert INSTANCE = Mappers.getMapper(VehicleConvert.class);

    /**
     * 转换为完整响应 VO
     */
    default VehicleRespVO convert(VehicleBaseDO base, VehicleLocationDO location,
                                   VehicleBusinessDO business, VehicleStatusDO status) {
        VehicleRespVO vo = new VehicleRespVO();
        
        // 基础信息
        if (base != null) {
            vo.setId(base.getId());
            vo.setPlateNo(base.getPlateNo());
            vo.setVehicleNo(base.getVehicleNo());
            vo.setVin(base.getVin());
            vo.setVehicleModelId(base.getVehicleModelId());
            vo.setRegionProvince(base.getRegionProvince());
            vo.setRegionCity(base.getRegionCity());
            vo.setEngineNo(base.getEngineNo());
            vo.setRegisterDate(base.getRegisterDate());
            vo.setPurchaseDate(base.getPurchaseDate());
            vo.setPurchasePrice(base.getPurchasePrice());
            vo.setColor(base.getColor());
            vo.setYear(base.getYear());
            vo.setMileage(base.getMileage());
            vo.setInspectExpire(base.getInspectExpire());
            vo.setScrapDate(base.getScrapDate());
            vo.setCreateTime(base.getCreateTime());
        }
        
        // 位置信息
        if (location != null) {
            vo.setParkingId(location.getParkingId());
            vo.setParkingName(location.getParkingName());
            vo.setParkingSpace(location.getParkingSpace());
            vo.setLocation(location.getLocation());
            vo.setLatitude(location.getLatitude());
            vo.setLongitude(location.getLongitude());
            vo.setGpsTime(location.getGpsTime());
            vo.setEntryTime(location.getEntryTime());
            vo.setExitTime(location.getExitTime());
        }
        
        // 业务信息
        if (business != null) {
            vo.setCustomerId(business.getCustomerId());
            vo.setDepartmentId(business.getDepartmentId());
            vo.setManagerId(business.getManagerId());
            vo.setContractId(business.getContractId());
            vo.setOwnership(business.getOwnership());
            vo.setDeliveryDate(business.getDeliveryDate());
            vo.setReturnDate(business.getReturnDate());
            vo.setMonthlyRent(business.getMonthlyRent());
            vo.setDeposit(business.getDeposit());
        }
        
        // 状态信息
        if (status != null) {
            vo.setStatus(status.getStatus());
            vo.setOperateStatus(status.getOperateStatus());
            vo.setStorageStatus(status.getStorageStatus());
            vo.setOutStatus(status.getOutStatus());
            vo.setPreemptStatus(status.getPreemptStatus());
            vo.setPrepareStatus(status.getPrepareStatus());
            vo.setTransferStatus(status.getTransferStatus());
            vo.setRepairStatus(status.getRepairStatus());
            vo.setLicenseStatus(status.getLicenseStatus());
            vo.setScrapStatus(status.getScrapStatus());
            vo.setOnlineStatus(status.getOnlineStatus());
            vo.setIsPrepared(status.getIsPrepared());
            vo.setIsDelivered(status.getIsDelivered());
            vo.setIsReturned(status.getIsReturned());
            vo.setLastMaintainDate(status.getLastMaintainDate());
            vo.setNextMaintainDate(status.getNextMaintainDate());
            vo.setLastInspectDate(status.getLastInspectDate());
            vo.setNextInspectDate(status.getNextInspectDate());
            vo.setInsuranceExpireDate(status.getInsuranceExpireDate());
        }
        
        return vo;
    }

    /**
     * 转换为精简响应 VO
     */
    default VehicleSimpleRespVO convertSimple(VehicleBaseDO base) {
        if (base == null) {
            return null;
        }
        VehicleSimpleRespVO vo = new VehicleSimpleRespVO();
        vo.setId(base.getId());
        vo.setVin(base.getVin());
        vo.setPlateNo(base.getPlateNo());
        return vo;
    }

    /**
     * 批量转换为精简响应 VO
     */
    default List<VehicleSimpleRespVO> convertSimpleList(List<VehicleBaseDO> list) {
        return list.stream().map(this::convertSimple).toList();
    }

}
