import { PvpEnemies, PvpOtherHeroes, WarStar } from "../../domain/dbGeneral";
import { GuildType } from "../../db/Guild";
import { RoleType } from "../../db/Role";
import { WAR_TYPE } from "../../consts";
import { gameData } from "../../pubUtils/data";
import { EXTERIOR } from "../../pubUtils/dicParam";

export class PlayerDetailHero {
    actorId: number;
    lv: number;
    star: number;
    colorStar: number;
    quality: number;
    score: number;

    setPvpHeroInfo?(hero: PvpEnemies|PvpOtherHeroes) {
        this.actorId = hero.actorId;
        this.lv = hero.lv;
        this.star = hero.star;
        this.colorStar = hero.colorStar;
        this.quality = hero.quality;
        this.score = hero.score;
    }
}

class PlayerDetailBattle {
    main: string[] = [];
    tower: string[] = [];
    pvp: string[] = [];

    constructor(warStar: WarStar[], pvp: number, tower: number) {
        let main = 0;
        for(let { id, warType } of warStar) {
            if(warType == WAR_TYPE.NORMAL) {
                if(id > main) main = id;
            }
        }
        let curDicWar = gameData.war.get(main);
        if(curDicWar) {
            this.main = curDicWar.detailUIBg;
        }
        this.pvp.push(pvp.toString());
        this.tower.push(tower.toString());

    }
}

export class PlayerDetail {
    roleId: string;
    roleName: string;
    lv: number;
    title?: number = 1;
    head?: number = EXTERIOR.EXTERIOR_FACE;
    frame?: number = EXTERIOR.EXTERIOR_FACECASE;
    spine?: number = EXTERIOR.EXTERIOR_APPEARANCE;

    score?: number = 0;
    pLv?: number = 1;
    defCe?: number = 0;

    heroes: PlayerDetailHero[];
    rank?:number = 0;
    
    battle?: PlayerDetailBattle = new PlayerDetailBattle([], 0, 0);

    constructor(detail: PlayerDetail) {
        if(detail.roleId) this.roleId = detail.roleId;
        if(detail.roleName) this.roleName = detail.roleName;
        if(detail.lv) this.lv = detail.lv;
        if(detail.title) this.title = detail.title;
        if(detail.head) this.head = detail.head;
        if(detail.frame) this.frame = detail.frame;
        if(detail.spine) this.spine = detail.spine;
        if(detail.score) this.score = detail.score;
        if(detail.pLv) this.pLv = detail.pLv;
        if(detail.defCe) this.defCe = detail.defCe;
        if(detail.heroes) this.heroes = detail.heroes;
        if(detail.rank) this.rank = detail.rank;
    }

    setWarStar?(warStar: WarStar[], pvp: number, tower: number) {
        this.battle = new PlayerDetailBattle(warStar, pvp, tower);
    }
}

// 军团返回
export class GuildMainInfo {
    code: string;              // 军团唯一编号
    icon: number;              // 头像
    name: string;              // 军团名
    lv: number;                // 等级
    memberCnt: number;         // 人数
    isAuto: boolean;           // 是否是自动加入
    ceLimit: number;           // 战力条件
    
    constructor(guild: GuildType) {
        this.code = guild.code;
        this.icon = guild.icon;
        this.name = guild.name;
        this.lv = guild.lv;
        this.memberCnt = guild.memberCnt;
        this.ceLimit = guild.ceLimit;
        this.isAuto = guild.isAuto;
    }
}

// getGuildList里的返回
export class GuildListInfo extends GuildMainInfo {
    leader: string;            // 团长名
    hasApply: boolean = false;         // 是否有申请过
    
    constructor(guild: GuildType) {
        super(guild);
        let leader = <RoleType>guild.leader;
        if(leader) this.leader = leader.roleName;
    }

    setApply(hasApply: boolean) {
        this.hasApply = hasApply;
    }
}
