using PSO2SERVER.Database;
using PSO2SERVER.Models;

namespace PSO2SERVER.Protocol.Packets
{
    internal class GuildInfoPacket : Packet
    {
        private readonly Character _character;

        public GuildInfoPacket(Character character)
        {
            _character = character;
        }

        #region implemented abstract members of Packet

        public override byte[] Build()
        {
            var writer = new PacketWriter();

            writer.Write((byte) 1); // Always 1? 可能是公会ID uint 涵盖下面3字节

            // Padding? Or the above is actually a uint
            for (var i = 0; i < 3; i++)
                writer.Write((byte) 0);

            // Character ID
            writer.Write((uint) _character.CharacterID);

            // Padding?
            for (var i = 0; i < 4; i++)
                writer.Write((byte) 0);

            // Nickname
            // TODO: The above and below may be switched around, need more data
            writer.WriteFixedLengthUtf16(_character.Account.Nickname, 16);

            // Padding?
            for (var i = 0; i < 36; i++)
                writer.Write((byte) 0);

            // Accounts name
            writer.WriteFixedLengthUtf16(_character.Name, 16);

            // Unknown?
            for (var i = 0; i < 24; i++)
                writer.Write((byte) 0);

            // Team Name
            // We don't actually have team names anywhere, just dump a test here
            writer.WriteFixedLengthUtf16("TEAMNAME", 16);

            // Unknown
            // Somewhere in here is likely a Team ID
            for (var i = 0; i < 32; i++)
                writer.Write((byte) 0);

            return writer.ToArray();
        }

        public override PacketHeader GetHeader()
        {
            return new PacketHeader(0x1C, 0x1F, PacketFlags.None);
        }

        #endregion
    }
}