package com.usky.sas.service.impl;

import com.usky.common.mybatis.core.AbstractCrudService;
import com.usky.sas.domain.SasUsbEvent;
import com.usky.sas.enums.SystemTypeCodeEnum;
import com.usky.sas.mapper.SasUsbEventMapper;
import com.usky.sas.service.SasMapService;
import com.usky.sas.service.SasUsbEventService;
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;

/**
 * USB事件服务实现
 */
@Service
public class SasUsbEventServiceImpl extends AbstractCrudService<SasUsbEventMapper, SasUsbEvent> implements SasUsbEventService {

    @Autowired
    private SasMapService sasMapService;

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

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

    @Override
    public MapInfoVo getMapInfo(String mapId) {
        MapInfoVo vo = sasMapService.getMapInfo(mapId);
        if (vo == null || vo.getType() == null || vo.getType() != SystemTypeCodeEnum.usbalarm.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.usbalarm.getCode()) {
            throw new IllegalArgumentException("仅支持修改视频导出防护（USB）模块的地图");
        }
        request.setType(SystemTypeCodeEnum.usbalarm.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.usbalarm.getCode()) {
            throw new IllegalArgumentException("仅支持删除视频导出防护（USB）模块的地图");
        }
        sasMapService.delete(id);
    }
}