﻿//----------------------
// <auto-generated>
// </auto-generated>
//----------------------







export class Exception implements IException {
    message!: string;
    innerException!: Exception | undefined;
    source!: string | undefined;
    stackTrace!: string | undefined;

    constructor(data?: IException) {
        if (data) {
            for (var property in data) {
                if (data.hasOwnProperty(property))
                    (this as any)[property] = (data as any)[property];
            }
        }
    }

    init(_data?: any) {
        if (_data) {
            this.message = _data["Message"];
            this.innerException = _data["InnerException"] ? Exception.fromJS(_data["InnerException"]) : undefined as any;
            this.source = _data["Source"];
            this.stackTrace = _data["StackTrace"];
        }
    }

    static fromJS(data: any): Exception {
        data = typeof data === 'object' ? data : {};
        let result = new Exception();
        result.init(data);
        return result;
    }

    toJSON(data?: any) {
        data = typeof data === 'object' ? data : {};
        data["Message"] = this.message;
        data["InnerException"] = this.innerException ? this.innerException.toJSON() : undefined as any;
        data["Source"] = this.source;
        data["StackTrace"] = this.stackTrace;
        return data;
    }
}

export interface IException {
    message: string;
    innerException: Exception | undefined;
    source: string | undefined;
    stackTrace: string | undefined;
}

export class ExceptionBase extends Exception implements IExceptionBase {
    foo!: string | undefined;

    protected _discriminator: string;

    constructor(data?: IExceptionBase) {
        super(data);
        this._discriminator = "ExceptionBase";
    }

    override init(_data?: any) {
        super.init(_data);
        if (_data) {
            this.foo = _data["Foo"];
        }
    }

    static override fromJS(data: any): ExceptionBase {
        data = typeof data === 'object' ? data : {};
        if (data["kind"] === "MyException") {
            let result = new MyException();
            result.init(data);
            return result;
        }
        let result = new ExceptionBase();
        result.init(data);
        return result;
    }

    override toJSON(data?: any) {
        data = typeof data === 'object' ? data : {};
        data["kind"] = this._discriminator;
        data["Foo"] = this.foo;
        super.toJSON(data);
        return data;
    }
}

export interface IExceptionBase extends IException {
    foo: string | undefined;
}

/** Foobar. */
export class MyException extends ExceptionBase implements IMyException {
    bar!: string | undefined;

    constructor(data?: IMyException) {
        super(data);
        this._discriminator = "MyException";
    }

    override init(_data?: any) {
        super.init(_data);
        if (_data) {
            this.bar = _data["Bar"];
        }
    }

    static override fromJS(data: any): MyException {
        data = typeof data === 'object' ? data : {};
        let result = new MyException();
        result.init(data);
        return result;
    }

    override toJSON(data?: any) {
        data = typeof data === 'object' ? data : {};
        data["Bar"] = this.bar;
        super.toJSON(data);
        return data;
    }
}

/** Foobar. */
export interface IMyException extends IExceptionBase {
    bar: string | undefined;
}

export class ExceptionContainer implements IExceptionContainer {
    exception!: ExceptionBase | undefined;

    constructor(data?: IExceptionContainer) {
        if (data) {
            for (var property in data) {
                if (data.hasOwnProperty(property))
                    (this as any)[property] = (data as any)[property];
            }
        }
    }

    init(_data?: any) {
        if (_data) {
            this.exception = _data["Exception"] ? ExceptionBase.fromJS(_data["Exception"]) : undefined as any;
        }
    }

    static fromJS(data: any): ExceptionContainer {
        data = typeof data === 'object' ? data : {};
        let result = new ExceptionContainer();
        result.init(data);
        return result;
    }

    toJSON(data?: any) {
        data = typeof data === 'object' ? data : {};
        data["Exception"] = this.exception ? this.exception.toJSON() : undefined as any;
        return data;
    }
}

export interface IExceptionContainer {
    exception: ExceptionBase | undefined;
}