
import { NativeModules, Platform } from "react-native";

const { MPosUDPSettingProxy } = NativeModules

export class UDPSetting {

    private readonly isWindows: boolean;

    constructor() {
        this.isWindows = Platform.OS === 'windows';
    }

    static async getNetworkInfos(): Promise<string> {
        if (Platform.OS === 'android' || Platform.OS === "ios") {
            return await MPosUDPSettingProxy.getNetworkInfos();
        }
        else {
            throw Error("not implemented yet")
        }
    }

    static async setNetworkInfo(object : UDPSettingData, timeout : number = 3) : Promise<Number> {
        if (Platform.OS === 'android') {
            return await MPosUDPSettingProxy.setNetworkInfo(object, timeout);    
        } 
        else if (Platform.OS === "ios") {
            return await MPosUDPSettingProxy.setNetworkInfo(
                object.macAddress,
                object.ipAddress,
                object.subnetMask,
                object.gateway,
                object.useDhcp ? 1 : 0,
                object.portNumber,
                object.inactivityTime,
                object.useHttps ? 1 : 0,
                object.baudrate,
                object.systemName,
                object.firmwareVersion,
                timeout
            );
        }
        else {
            throw Error("not implemented yet")
        }
    }
}

export interface UDPSettingData {
    macAddress : string,
    ipAddress : string,
    subnetMask : string,
    gateway : string,
    portNumber : number,
    baudrate : number,
    firmwareVersion : number,
    useDhcp : Boolean,
    inactivityTime : number,
    useHttps : Boolean,
    systemName : string
}