import { RoleType } from '../../db/Role';
import { ServerlistType } from '../../db/Serverlist';

export class ServerParam {
    id: number;          // 区号
    serverId: number;    // 显示的区号
    serverStr: string;   // 显示的区号 S1
    name: string;        // 区名  
    host: string = '';        // pinus地址
    port: number = 0;        // pinus端口
    status: number;      // 状态
    openTime: number;    // 开服时间

    constructor(server: ServerlistType) {
        this.id = server.id;
        this.serverId = server.serverId;
        this.serverStr = `${server.prefix}${server.serverId}`;
        this.name = server.name;
        this.status = server.status;
        this.openTime = server.openTime;
    }
}

export class GroupParam {
    groupId: number;        // 大区号
    groupName: string;      // 大区名
    groupStr: string;      // 大区内小区编号 S1-S10
    servers: ServerParam[];      // 区

    constructor(server: ServerlistType) {
        this.groupId = server.groupId;
        this.groupName = server.groupName;
        this.groupStr = `${server.prefix}${server.serverId}`;
        this.servers = new Array<ServerParam>();
    }

    public pushServer(server: ServerlistType) {
        let srv = new ServerParam(server);
        this.servers.push(srv);
        this.servers.sort((a, b) => b.serverId - a.serverId);
        let min = this.servers[this.servers.length - 1];
        let max = this.servers[0];
        this.groupStr = `${min.serverStr}-${max.serverStr}`
    }
}

export class ServerParamWithRole extends ServerParam {
    groupId: number;        // 大区号
    groupName: string;      // 大区名

    roleId: string;          // 玩家账号
    roleName: string;        // 玩家名
    head: number;         // 头像
    frame: number;            // 相框
    spine: number;            // 形象
    lv: number;              // 等级
    updatedAt: Date;

    constructor(role: RoleType, server: ServerlistType) {
        super(server);
        this.groupId = server.groupId;
        this.groupName = server.groupName;

        this.roleId = role.roleId;
        this.roleName = role.roleName;
        this.head = role.head;
        this.frame = role.frame;
        this.spine = role.spine;
        this.lv = role.lv;
        this.updatedAt = role.updatedAt;
    } 
}