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







export class MyItem implements IMyItem {
    name!: string;
    age!: number;

    constructor(data?: IMyItem) {
        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.name = _data["name"];
            this.age = _data["age"];
        }
    }

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

    toJSON(data?: any) {
        data = typeof data === 'object' ? data : {};
        data["name"] = this.name;
        data["age"] = this.age;
        return data;
    }
}

export interface IMyItem {
    name: string;
    age: number;
}

export class Test implements ITest {
    myDict!: { [key: string]: MyItem; };

    [key: string]: any;

    constructor(data?: ITest) {
        if (data) {
            for (var property in data) {
                if (data.hasOwnProperty(property))
                    (this as any)[property] = (data as any)[property];
            }
            if (data.myDict) {
                this.myDict = {};
                for (let key in data.myDict) {
                    if (data.myDict.hasOwnProperty(key)) {
                        let item = data.myDict[key];
                        this.myDict[key] = item && !(item as any).toJSON ? new MyItem(item) : item as MyItem;
                    }
                }
            }
        }
    }

    init(_data?: any) {
        if (_data) {
            for (var property in _data) {
                if (_data.hasOwnProperty(property))
                    this[property] = _data[property];
            }
            if (_data["myDict"]) {
                this.myDict = {} as any;
                for (let key in _data["myDict"]) {
                    if (_data["myDict"].hasOwnProperty(key))
                        (this.myDict as any)![key] = _data["myDict"][key] ? MyItem.fromJS(_data["myDict"][key]) : new MyItem();
                }
            }
        }
    }

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

    toJSON(data?: any) {
        data = typeof data === 'object' ? data : {};
        for (var property in this) {
            if (this.hasOwnProperty(property))
                data[property] = this[property];
        }
        if (this.myDict) {
            data["myDict"] = {};
            for (let key in this.myDict) {
                if (this.myDict.hasOwnProperty(key))
                    (data["myDict"] as any)[key] = this.myDict[key] ? this.myDict[key].toJSON() : undefined as any;
            }
        }
        return data;
    }
}

export interface ITest {
    myDict: { [key: string]: IMyItem; };

    [key: string]: any;
}