package net.geedge.api.util;

import lombok.Data;
import net.geedge.common.T;

@Data
public class AdbDevice implements Comparable<AdbDevice> {

    private String serial;
    private boolean available;


    public AdbDevice(String line) {
        String[] array = line.split(" ");
        serial = array[0];

        for (int i = 1; i < array.length; i++) {
            if (!T.StrUtil.isEmpty(array[i])) {
                available = "device".equals(array[i]);
                break;
            }
        }
    }

    public boolean isAvailable() {
        return available;
    }

    @Override
    public boolean equals(Object object) {
        if (object instanceof AdbDevice)
            return serial.equals(((AdbDevice) object).serial) && available == ((AdbDevice) object).available;
        return false;
    }

    @Override
    public int compareTo(AdbDevice device) {
        return serial.compareTo(device.serial);
    }

}