import {
    HWMember, HWMemberStat, HWWeekStat,
    HWGuildRaid, HWMemberHeroes, HWMemberTitans
} from '@models';

export class MemberViewModel {
    member: HWMember;

    constructor(member: HWMember) {
        this.member = member;
    }

    getId(): string {
        return this.member.id;
    }

    getName(): string {
        return this.member.name;
    }

    getClanTitle(): string {
        return this.member.clanTitle;
    }

    getServerId(): string {
        return this.member.serverId;
    }

    getLastLoginTime(): string {
        return this.member.lastLoginTime;
    }

    getLevel(): string {
        return this.member.level;
    }

    getAllowPm(): string {
        return this.member.allowPm;
    }

    getAvatarId(): string {
        return this.member.avatarId;
    }

    getClanIcon() {
        return this.member.clanIcon;
    }

    getClanId(): string {
        return this.member.clanId;
    }

    getClanRole(): string {
        return this.member.clanRole;
    }

    isCommander(): boolean {
        return this.member.commander;
    }

    getFrameId(): number {
        return this.member.frameId;
    }

    isChatModerator(): boolean {
        return this.member.isChatModerator;
    }

    getLeagueId(): number {
        return this.member.leagueId;
    }

    canShowProfile(): boolean {
        return this.member.showProfile;
    }

    isChampion(): boolean {
        return this.member.champion;
    }

    getMemberHeroes(): HWMemberHeroes {
        return this.member.heroes;
    }

    getMemberTitans(): HWMemberTitans {
        return this.member.titans;
    }

    getStat(): HWMemberStat {
        return this.member.stat;
    }

    getInactivity() {
        return this.member.inactivity;
    }

    getAdventureSum(): number {
        return this.member.adventureSum;
    }

    getClanGiftsSum(): number {
        return this.member.clanGiftsSum;
    }

    getClanWarSum(): number {
        return this.member.clanWarSum;
    }

    getWeekStat(): HWWeekStat {
        return this.member.weekStat;
    }

    getScore(): number {
        return this.member.score;
    }

    getScoreGifts(): number {
        return this.member.scoreGifts;
    }

    getWarGifts(): number {
        return this.member.warGifts;
    }

    getRewards(): number {
        return this.member.rewards;
    }

    getRaids(): HWGuildRaid[] {
        return this.member.raids;
    }

    getRaidsInfo() {
        return this.member.raidsInfo;
    }
}

export class MembersViewModel {
    members: MemberViewModel[];

    constructor(members: HWMember[]) {
        this.members = members.map(member => new MemberViewModel(member));
    }

    getMembers(): MemberViewModel[] {
        return this.members;
    }

    getMemberCount(): number {
        return this.members.length;
    }

    getMemberById(id: string): MemberViewModel | undefined {
        return this.members.find(member => member.getId() === id);
    }

    getMemberByName(name: string): MemberViewModel | undefined {
        return this.members.find(member => member.getName() === name);
    }

    getMembersByClanRole(clanRole: string): MemberViewModel[] {
        return this.members.filter(member => member.getClanRole() === clanRole);
    }

    getCommandeurs(): MemberViewModel[] {
        return this.members.filter(member => member.isCommander());
    }

    getChampions(): MemberViewModel[] {
        return this.members.filter(member => member.isChampion());
    }

    getMembersByLevel(level: string): MemberViewModel[] {
        return this.members.filter(member => member.getLevel() === level);
    }

    getMembersWithLowestScore(): MemberViewModel[] {
        if (this.members.length === 0) return [];
        const minScore = Math.min(...this.members.map(m => m.getScore()));
        return this.members.filter(member => member.getScore() === minScore);
    }

    getMembersWithHighestScore(): MemberViewModel[] {
        if (this.members.length === 0) return [];
        const maxScore = Math.max(...this.members.map(m => m.getScore()));
        return this.members.filter(member => member.getScore() === maxScore);
    }

    getTotalScore(): number {
        return this.members.reduce((sum, member) => sum + member.getScore(), 0);
    }

    getAverageScore(): number {
        if (this.members.length === 0) return 0;
        return this.getTotalScore() / this.members.length;
    }

    getTotalAdventureSum(): number {
        return this.members.reduce((sum, member) => sum + member.getAdventureSum(), 0);
    }

    getTotalClanWarSum(): number {
        return this.members.reduce((sum, member) => sum + member.getClanWarSum(), 0);
    }

    getTotalClanGiftsSum(): number {
        return this.members.reduce((sum, member) => sum + member.getClanGiftsSum(), 0);
    }
}
