import Packet from "../packet";
import Stream from "../stream";


export class PacketGroupInfo extends Packet { 

    private groupId: string = "";
    private members: string[] = [];

    public getPacketId(): number {
        return 0x12;
    }

    public _receive(stream: Stream): void {
        this.groupId = stream.readString();
        const membersCount = stream.readInt16();
        this.members = [];
        for(let i = 0; i < membersCount; i++) {
            this.members.push(stream.readString());
        }
    }

    public _send(): Promise<Stream> | Stream {
        const stream = new Stream();
        stream.writeInt16(this.getPacketId());
        stream.writeString(this.groupId);
        stream.writeInt16(this.members.length);
        this.members.forEach((member) => {
            stream.writeString(member);
        });
        return stream;
    }

    public getGroupId(): string {
        return this.groupId;
    }

    public setGroupId(groupId: string): void {
        this.groupId = groupId;
    }

    public setMembers(members: string[]): void {
        this.members = members;
    }

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

}