package com.usky.sas.service.impl;

import com.usky.common.mybatis.core.AbstractCrudService;
import com.usky.sas.domain.SasPatrolEvent;
import com.usky.sas.enums.SystemTypeCodeEnum;
import com.usky.sas.mapper.SasPatrolEventMapper;
import com.usky.sas.service.SasMapService;
import com.usky.sas.service.SasPatrolEventService;
import com.usky.sas.service.vo.MapSaveRequest;
import com.usky.sas.service.vo.MapTreeItem;
import com.usky.sas.service.vo.MapInfoVo;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 实时电子巡检事件服务实现
 */
@Service
public class SasPatrolEventServiceImpl extends AbstractCrudService<SasPatrolEventMapper, SasPatrolEvent> implements SasPatrolEventService {

    @Autowired
    private SasMapService sasMapService;

    @Override
    public String addMap(MapSaveRequest request) {
        request.setType(SystemTypeCodeEnum.patrol.getCode());
        return sasMapService.create(request);
    }

    @Override
    public List<MapTreeItem> getMapTree() {
        return sasMapService.getMapTreeByType(SystemTypeCodeEnum.patrol.getCode());
    }

    @Override
    public MapInfoVo getMapInfo(String mapId) {
        MapInfoVo vo = sasMapService.getMapInfo(mapId);
        if (vo == null || vo.getType() == null || vo.getType() != SystemTypeCodeEnum.patrol.getCode()) {
            return null;
        }
        return vo;
    }

    @Override
    public void updateMap(String id, MapSaveRequest request) {
        MapInfoVo vo = sasMapService.getMapInfo(id);
        if (vo == null || vo.getType() == null || vo.getType() != SystemTypeCodeEnum.patrol.getCode()) {
            throw new IllegalArgumentException("仅支持修改实时电子巡检模块的地图");
        }
        request.setType(SystemTypeCodeEnum.patrol.getCode());
        sasMapService.update(id, request);
    }

    @Override
    public void deleteMap(String id) {
        MapInfoVo vo = sasMapService.getMapInfo(id);
        if (vo == null || vo.getType() == null || vo.getType() != SystemTypeCodeEnum.patrol.getCode()) {
            throw new IllegalArgumentException("仅支持删除实时电子巡检模块的地图");
        }
        sasMapService.delete(id);
    }
}