package net.northking.cctp.se.device.bean;

import lombok.extern.slf4j.Slf4j;
import net.northking.cctp.element.core.DeviceDriver;
import net.northking.cctp.se.device.service.DeviceConnection;

import java.util.Map;

@SuppressWarnings("ALL")
@Slf4j
public abstract class AbstractDeviceConnection implements DeviceConnection {
    protected String deviceToken;
    protected DeviceDriver deviceDriver;
    protected DeviceInfo deviceInfo;

    public AbstractDeviceConnection(String deviceToken,DeviceInfo deviceInfo) throws Exception{
        this.deviceToken = deviceToken;
        this.deviceInfo = deviceInfo;
        initDriver();
    }
    @Override
    public String getDeviceId() {
        return deviceInfo.getDeviceId();
    }

    @Override
    public DeviceDriver getDeviceDriver() {
        return deviceDriver;
    }

    @Override
    public DeviceInfo getDeviceInfo() {
        return deviceInfo;
    }

    @Override
    public void close() {
        deviceDriver.destroy();
        log.debug("AbstractDeviceConnection.close:设备【{}】的driver释放",deviceInfo.getDeviceId());
        deviceDriver = null;
    }

    @Override
    public String getDeviceToken() {
        return deviceToken;
    }

    protected abstract void initDriver() throws Exception;

    @Override
    public String snapshotAllScreen(String userToken, String taskId) {
        return null;
    }

    @Override
    public boolean reconnect() {
        return false;
    }

    @Override
    public void recordDevicePer(Map<String, Object> params) {

    }

    @Override
    public DevicePerInfo stopRecordDevicePer() {
        return null;
    }
}
