/* THIS (.ts) FILE IS GENERATED BY TypedSignalR.Client.TypeScript */
/* eslint-disable */
/* tslint:disable */
// @ts-nocheck
import type { HubConnection, IStreamResult, Subject } from '@microsoft/signalr';
import type { IJtagHub, IProgressHub, IJtagReceiver, IProgressReceiver } from './server.Hubs';
import type { ProgressInfo } from '../server.Hubs';


// components

export type Disposable = {
    dispose(): void;
}

export type HubProxyFactory<T> = {
    createHubProxy(connection: HubConnection): T;
}

export type ReceiverRegister<T> = {
    register(connection: HubConnection, receiver: T): Disposable;
}

type ReceiverMethod = {
    methodName: string,
    method: (...args: any[]) => void
}

class ReceiverMethodSubscription implements Disposable {

    public constructor(
        private connection: HubConnection,
        private receiverMethod: ReceiverMethod[]) {
    }

    public readonly dispose = () => {
        for (const it of this.receiverMethod) {
            this.connection.off(it.methodName, it.method);
        }
    }
}

// API

export type HubProxyFactoryProvider = {
    (hubType: "IJtagHub"): HubProxyFactory<IJtagHub>;
    (hubType: "IProgressHub"): HubProxyFactory<IProgressHub>;
}

export const getHubProxyFactory = ((hubType: string) => {
    if(hubType === "IJtagHub") {
        return IJtagHub_HubProxyFactory.Instance;
    }
    if(hubType === "IProgressHub") {
        return IProgressHub_HubProxyFactory.Instance;
    }
}) as HubProxyFactoryProvider;

export type ReceiverRegisterProvider = {
    (receiverType: "IJtagReceiver"): ReceiverRegister<IJtagReceiver>;
    (receiverType: "IProgressReceiver"): ReceiverRegister<IProgressReceiver>;
}

export const getReceiverRegister = ((receiverType: string) => {
    if(receiverType === "IJtagReceiver") {
        return IJtagReceiver_Binder.Instance;
    }
    if(receiverType === "IProgressReceiver") {
        return IProgressReceiver_Binder.Instance;
    }
}) as ReceiverRegisterProvider;

// HubProxy

class IJtagHub_HubProxyFactory implements HubProxyFactory<IJtagHub> {
    public static Instance = new IJtagHub_HubProxyFactory();

    private constructor() {
    }

    public readonly createHubProxy = (connection: HubConnection): IJtagHub => {
        return new IJtagHub_HubProxy(connection);
    }
}

class IJtagHub_HubProxy implements IJtagHub {

    public constructor(private connection: HubConnection) {
    }

    public readonly setBoundaryScanFreq = async (freq: number): Promise<boolean> => {
        return await this.connection.invoke("SetBoundaryScanFreq", freq);
    }

    public readonly startBoundaryScan = async (freq: number): Promise<boolean> => {
        return await this.connection.invoke("StartBoundaryScan", freq);
    }

    public readonly stopBoundaryScan = async (): Promise<boolean> => {
        return await this.connection.invoke("StopBoundaryScan");
    }
}

class IProgressHub_HubProxyFactory implements HubProxyFactory<IProgressHub> {
    public static Instance = new IProgressHub_HubProxyFactory();

    private constructor() {
    }

    public readonly createHubProxy = (connection: HubConnection): IProgressHub => {
        return new IProgressHub_HubProxy(connection);
    }
}

class IProgressHub_HubProxy implements IProgressHub {

    public constructor(private connection: HubConnection) {
    }

    public readonly join = async (taskId: string): Promise<boolean> => {
        return await this.connection.invoke("Join", taskId);
    }
}


// Receiver

class IJtagReceiver_Binder implements ReceiverRegister<IJtagReceiver> {

    public static Instance = new IJtagReceiver_Binder();

    private constructor() {
    }

    public readonly register = (connection: HubConnection, receiver: IJtagReceiver): Disposable => {

        const __onReceiveBoundaryScanData = (...args: [Partial<Record<string, boolean>>]) => receiver.onReceiveBoundaryScanData(...args);

        connection.on("OnReceiveBoundaryScanData", __onReceiveBoundaryScanData);

        const methodList: ReceiverMethod[] = [
            { methodName: "OnReceiveBoundaryScanData", method: __onReceiveBoundaryScanData }
        ]

        return new ReceiverMethodSubscription(connection, methodList);
    }
}

class IProgressReceiver_Binder implements ReceiverRegister<IProgressReceiver> {

    public static Instance = new IProgressReceiver_Binder();

    private constructor() {
    }

    public readonly register = (connection: HubConnection, receiver: IProgressReceiver): Disposable => {

        const __onReceiveProgress = (...args: [ProgressInfo]) => receiver.onReceiveProgress(...args);

        connection.on("OnReceiveProgress", __onReceiveProgress);

        const methodList: ReceiverMethod[] = [
            { methodName: "OnReceiveProgress", method: __onReceiveProgress }
        ]

        return new ReceiverMethodSubscription(connection, methodList);
    }
}

