package com.yc.ship.module.otc.convert.scheduling;

import com.yc.ship.framework.common.util.collection.CollectionUtils;
import com.yc.ship.framework.common.util.collection.MapUtils;
import com.yc.ship.module.otc.controller.admin.storescheduling.user.StoreSchedulingUserRespVO;
import com.yc.ship.module.otc.dal.dataobject.storescheduling.StoreSchedulingDO;
import com.yc.ship.module.system.api.user.dto.AdminUserRespDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.Map;

/**
 * @author YC
 */
@Mapper
public interface SchedulingUserConvert {

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

    default List<StoreSchedulingUserRespVO> convertRespListByUser(List<StoreSchedulingUserRespVO> list, Map<Long, AdminUserRespDTO> map) {
        return CollectionUtils.convertList(list, schedulingUser -> {
            MapUtils.findAndThen(map, schedulingUser.getUserId(), user -> {
                schedulingUser.setUserName(user.getNickname());
            });
            return schedulingUser;
        });
    }

    default List<StoreSchedulingUserRespVO> convertRespListByScheduling(List<StoreSchedulingUserRespVO> list, Map<Long, StoreSchedulingDO> map) {
        return CollectionUtils.convertList(list, schedulingUser -> {
            MapUtils.findAndThen(map, schedulingUser.getSchedulingId(), scheduling -> {
                schedulingUser.setSchedulingName(scheduling.getName());
                schedulingUser.setSchedulingTime(scheduling.getStartTime() + "~" + scheduling.getEndTime());
            });
            return schedulingUser;
        });
    }

}
