// https://wicg.github.io/serial/#serialport-interface
[Exposed=(DedicatedWorker,Window), SecureContext]
interface SerialPort : EventTarget {
    attribute EventHandler onconnect;
    attribute EventHandler ondisconnect;
    readonly attribute boolean connected;
    readonly attribute ReadableStream readable;
    readonly attribute WritableStream writable;

    SerialPortInfo getInfo();

    Promise<undefined> open(SerialOptions options);
    Promise<undefined> setSignals(optional SerialOutputSignals signals = {});
    Promise<SerialInputSignals> getSignals();
    Promise<undefined> close();
    Promise<undefined> forget();
};

// https://wicg.github.io/serial/#serialoptions-dictionary
dictionary SerialOptions {
    [EnforceRange] unsigned long baudRate;
    [EnforceRange] octet dataBits = 8;
    [EnforceRange] octet stopBits = 1;
    ParityType parity = "none";
    [EnforceRange] unsigned long bufferSize = 255;
    FlowControlType flowControl = "none";
};

// https://wicg.github.io/serial/#serialoutputsignals-dictionary
dictionary SerialOutputSignals {
    boolean dataTerminalReady;
    boolean requestToSend;
    boolean break;
};

// https://wicg.github.io/serial/#serialinputsignals-dictionary
dictionary SerialInputSignals {
    required boolean dataCarrierDetect;
    required boolean clearToSend;
    required boolean ringIndicator;
    required boolean dataSetReady;
};

// https://wicg.github.io/serial/#serialportinfo-dictionary
dictionary SerialPortInfo {
    unsigned short usbVendorId;
    unsigned short usbProductId;
    // FIXME: Should be a BluetoothServiceUUID
    DOMString bluetoothServiceClassId;
};

// https://wicg.github.io/serial/#paritytype-enum
enum ParityType {
    "none",
    "even",
    "odd"
};

// https://wicg.github.io/serial/#flowcontroltype-enum
enum FlowControlType {
    "none",
    "hardware"
};
