package com.rolandjamesaskew.shared.android.hardware.model;

import android.hardware.Sensor;

import java.io.Serializable;

/**
 * Created by Roland on 31/01/2017.
 *
 * Representative for device Sensors.
 */

public class SensorModel implements Serializable {

    public static final int NULL_SENSOR_TYPE = -999;
    public static final String NULL_SENSOR_VENDOR = "NullVendor";
    public static final int NULL_SENSOR_VERSION = -999;

    private final String mName;
    private final String mVendor;
    private final int mVersion;
    private final int mType;

    private SensorModel(Sensor pSensor)
    {
        mName = pSensor.getName();
        mType = pSensor.getType();
        mVendor = pSensor.getVendor();
        mVersion = pSensor.getVersion();
    }

    private SensorModel(String pName)
    {
        mName = pName;
        mType = SensorModel.NULL_SENSOR_TYPE;
        mVendor = SensorModel.NULL_SENSOR_VENDOR;
        mVersion = SensorModel.NULL_SENSOR_VERSION;
    }

    public static SensorModel newNullInstance()
    {
        return new SensorModel("NullSensorModel");
    }

    public static SensorModel newNullInstance(String pName)
    {
        return new SensorModel(pName);
    }

    public static SensorModel newInstance(Sensor pSensor)
    {
        return new SensorModel(pSensor);
    }

    public String getName() {
        return mName;
    }

    public String getVendor() {
        return mVendor;
    }

    public int getType() {
        return mType;
    }

    public int getVersion() {
        return mVersion;
    }

    public boolean isNullInstance()
    {
        return mVendor.equals(SensorModel.NULL_SENSOR_VENDOR)
                && mType == SensorModel.NULL_SENSOR_TYPE
                && mVersion == SensorModel.NULL_SENSOR_VERSION;
    }

    @Override
    public String toString() {
        return mName;
    }

    public boolean equals(Sensor pSensor) {
        return mName.equals(pSensor.getName()) &&
                mVendor.equals(pSensor.getVendor()) &&
                mVersion == pSensor.getVersion() &&
                mType == pSensor.getType();
    }
}
