package thyyxxk.webserver.service.dictionary;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import thyyxxk.webserver.dao.his.dictionary.ClinicRoomDictDao;
import thyyxxk.webserver.entity.dictionary.CodeName;
import thyyxxk.webserver.entity.outpatient.triage.MzfzZdDeptRoom;
import thyyxxk.webserver.service.hutoolcache.DeptCache;
import thyyxxk.webserver.utils.StringUtil;

import java.util.List;

@Service
public class ClinicRoomDictService {
    private final ClinicRoomDictDao dao;
    private final DeptCache deptCache;

    @Autowired
    public ClinicRoomDictService(ClinicRoomDictDao dao, DeptCache deptCache) {
        this.dao = dao;
        this.deptCache = deptCache;
    }

    public List<CodeName> getDeptList() {
        return dao.getDeptList();
    }

    public List<MzfzZdDeptRoom> getAllRooms() {
        return dao.getAllRooms();
    }

    public MzfzZdDeptRoom changeRoomInfo(MzfzZdDeptRoom room) {
        if (StringUtil.notBlank(room.getRoomCode())) {
            dao.updateRoomInfo(room);
        } else {
            room.setRoomCode(dao.getMaxRoomCode());
            dao.insertRoomInfo(room);
        }
        room.setDeptName(deptCache.getDeptName(room.getDeptCode()));
        return room;
    }

}
