package com.ruoyi.ss.card.service.impl;

import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.ss.card.domain.SsCardVO;
import com.ruoyi.ss.card.service.ISsCardAssembler;
import com.ruoyi.ss.room.domain.RoomVO;
import com.ruoyi.ss.room.service.IRoomService;
import com.ruoyi.ss.room.service.impl.RoomServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 卡券组装器
 *
 * @author qzz
 * @date 2025-03-03
 */
@Service
public class CardAssemblerImpl implements ISsCardAssembler {

    @Autowired
    private IRoomService roomService;


    /**
     * 拼接后台需要的卡券信息
     * @param list 列表
     */
    @Override
    public void assembleInfo(List<SsCardVO> list) {
        if(list.isEmpty()){
            return;
        }
        // 可用房间
        list.forEach(card -> {
            if (CollectionUtils.isEmptyElement(card.getAvailableRooms())) {
                return;
            }
            List<RoomVO> rooms = roomService.selectERoomByRoomIds(card.getAvailableRooms());
            StringBuilder sb = new StringBuilder();
            rooms.forEach(room -> {
                sb.append(room.getRoomName()).append(",");
            });
            card.setRoomNames(sb.substring(0, sb.length() - 1));
        });
    }
}
