package com.skr.mdm.api.equipment.service.impl;

import com.skr.mdm.api.equipment.annotation.UserStrategy;
import com.skr.mdm.api.equipment.service.UserStrategyService;
import com.skr.mdm.dao.AuCompanyDao;
import com.skr.mdm.dao.DeviceEquipmentDao;
import com.skr.mdm.enums.UserStrategyEnum;
import com.skr.mdm.result.ResponseResult;
import com.skr.mdm.entity.AuCompanyDO;
import com.skr.mdm.entity.DeviceEquipmentDO;
import com.skr.mdm.util.GaodeMapAPIUtil;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author nfq
 * @date 2023-02-02 16:23
 */
@UserStrategy(strategyType = UserStrategyEnum.GAODE_LIEYING_TERMINAL)
public class GaodeLieyingTerminalUserStrategyServiceImpl implements UserStrategyService {

    @Autowired
    private DeviceEquipmentDao equipmentDao;
    @Autowired
    private AuCompanyDao companyDao;

    @Override
    public ResponseResult getUserStrategy(Integer equipmentId) {
        DeviceEquipmentDO equipmentDO = equipmentDao.selectById(equipmentId);
        AuCompanyDO companyDO = companyDao.selectById(equipmentDO.getCompanyId());
        if (companyDO.getSid() == null) {
            return ResponseResult.failure("所在公司不支持猎鹰终端");
        }
        if (equipmentDO.getTid() == null) {
            return ResponseResult.failure("该设备未注册猎鹰终端");
        }
        return ResponseResult.success(GaodeMapAPIUtil.getTerminal(companyDO.getSid(), equipmentDO.getTid()));
    }
}
