
import Dictionary from "../Util/Dictionary";

export class CfgManager {
    private static instance: CfgManager;
    public static get Instance(): CfgManager {
        return this.instance || (this.instance = new CfgManager());
    }

    public sign: any;
    public GetSign(id: number) {
        if (this.sign) {
            return this.sign[id - 1];
        }
    }
    public rewards: any;
    public GetReward(id: number) {
        if (this.rewards) {
            for (let index = 0; index < this.rewards.length; index++) {
                const element = this.rewards[index];
                if (element.id == id) {
                    return element;
                }
            }
        }
    }

    public mission: any;
    public GetMission(id: number) {
        if (this.mission) {
            return this.mission[id - 1];
        }
        return null;
    }

    public enemyteam: any;
    public GetEnemyTeam(id: number) {
        if (this.enemyteam) {
            return this.enemyteam[id - 1];
        }
        return null;
    }

    public shoot: any;



    public role: any;
    public GetRole(id: number) {
        if (this.role) {
            return this.role[id - 1];
            // for (let index = 0; index < this.role.length; index++) {
            //     const element = this.role[index];
            //     if (id == element.role_id) {
            //         return element;
            //     }
            // }
        }
        return null;
    }

    public _level: any;
    public GetLevel(id) {
        if (this._level) {
            return this._level[id - 1];
        }
        return null;
    }

    public _road: any;
    public GetRoad(id) {
        if (this._road) {
            return this._road[id - 1];
        }
        return null;
    }
    public _block: any;
    public GetBlock(id) {
        if (this._block) {
            return this._block[id - 1];
        }
        return null;
    }
    public _thing: any;
    public GetThing(id) {
        if (this._thing) {
            return this._thing[id - 1];
        }
        return null;
    }
    public _atk: any;
    public GetAtk(id) {
        if (this._atk) {
            return this._atk[id - 1];
        }
        return null;
    }

    public _rate: any;
    public GetRate(id) {
        if (this._rate) {
            return this._rate[id - 1];
        }
        return null;
    }

    public car: any;
    public GetCar(id: number) {
        if (this.car) {
            return this.car[id - 1];
        }
        return null;
    }

    public _globe: any;
    public GetGlobe(key: string) {
        if (this._globe) {
            for (let index = 0; index < this._globe.length; index++) {
                const element = this._globe[index];
                if (element.key == key) {
                    return element.value;
                }
            }
        }
    }

    // public _hats: any;
    // public GetHat(id: number) {
    //     for (let index = 0; index < this._hats.length; index++) {
    //         const element = this._hats[index];
    //         if (element.id == id) {
    //             return element;
    //         }
    //     }
    // }
    // public glass: any;
    // public GetGlass(id: number) {
    //     for (let index = 0; index < this.glass.length; index++) {
    //         const element = this.glass[index];
    //         if (element.id == id) {
    //             return element;
    //         }
    //     }
    // }
    // public _body: any;
    // public GetBody(id: number) {
    //     for (let index = 0; index < this._body.length; index++) {
    //         const element = this._body[index];
    //         if (element.id == id) {
    //             return element;
    //         }
    //     }
    // }

    // public _leg: any;
    // public GetLeg(id: number) {
    //     for (let index = 0; index < this._leg.length; index++) {
    //         const element = this._leg[index];
    //         if (element.id == id) {
    //             return element;
    //         }
    //     }
    // }
    // public _themeGun: any;
    // public GetThemeGun(id: number) {
    //     for (let index = 0; index < this._themeGun.length; index++) {
    //         const element = this._themeGun[index];
    //         if (element.id == id) {
    //             return element;
    //         }
    //     }
    // }
    // public _gun: any;
    // public GetGun(id: number) {
    //     if (this._gun) {
    //         return this._gun[id - 1];
    //     }
    // }

    public _theme: any;
    public GetTheme(id) {
        if (this._theme) {
            return this._theme[id - 1];
            // for (let index = 0; index < this._theme.length; index++) {
            //     const element = this._theme[index];
            //     if (element.id == id) {
            //         return element;
            //     }
            // }
        }
        return null;
    }
    // private _theme;
    // public SetTheme(data) {
    //     this._theme = data;
    //     this._hats = [];
    //     this.glass = [];
    //     this._body = [];
    //     this._leg = [];
    //     this._themeGun = [];
    //     for (let index = 0; index < data.length; index++) {
    //         const element = data[index];
    //         if (element.type == ThemeType.Hat) {
    //             //if (element.prefab != "0")
    //             this._hats.push(element);
    //         } else if (element.type == ThemeType.Glass) {
    //             //if (element.prefab != "0")
    //             this.glass.push(element);
    //         } else if (element.type == ThemeType.Body) {
    //             this._body.push(element);
    //         } else if (element.type == ThemeType.Leg) {
    //             this._leg.push(element);
    //         } else if (element.type == ThemeType.Gun) {
    //             this._themeGun.push(element);
    //         }
    //     }
    // }


    public _lottery: any;
    public GetLottery(id: number) {
        if (this._lottery) {
            // for (let index = 0; index < this._lottery.length; index++) {
            //     const element = this._lottery[index];
            //     if (element.id == id) {
            //         return element;
            //     }
            // }
            return this._lottery[id - 1];
        }
        return null;
    }

    public _achievement: any;
    public GetAchievement(type: string, level: number): any {
        if (this._achievement) {
            for (let index = 0; index < this._achievement.length; index++) {
                if (this._achievement[index].type == type) {
                    if (this._achievement[index].level == level) {
                        return this._achievement[index];
                    }
                }
            }
        }
    }
    public GetTypeLevel(type: string): number {
        var count = 0;
        if (this._achievement) {
            for (let index = 0; index < this._achievement.length; index++) {
                if (this._achievement[index].type == type) {
                    count++;
                }
            }
            return count;
        }
    }
    private _achieveType: number;
    public GetachieveType(): number {
        if (this._achieveType == null) {
            if (this._achievement) {
                for (let index = 0; index < this._achievement.length; index++) {
                    this._achieveType = this._achievement[index].type;
                }
            }
        }
        return this._achieveType;
    }


}