using PSO2SERVER.Models;
using PSO2SERVER.Party;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PSO2SERVER.Protocol.Packets
{
    public class PartySettingsPacket : Packet
    {
        // Name of the party
        public string name { get; set; } = string.Empty;

        // Party password
        public string password { get; set; } = string.Empty;

        // Party comments
        public string comments { get; set; } = string.Empty;

        // Minimum acceptable level
        public byte min_level { get; set; } = 0;

        // Maximum acceptable level
        public byte max_level { get; set; } = 0;

        // Party playstyle
        public byte playstyle { get; set; } = 0;

        // Party flags
        public PartyFlags flags { get; set; } = new PartyFlags();

        // Unknown field, presumably a 64-bit unsigned integer
        public ulong unk { get; set; } = 0;

        public PartySettingsPacket()
        {
            // 初始化默认值
        }

        public PartySettingsPacket(PartySettingsPacket packet)
        {
            name = packet.name;
            password = packet.password;
            comments = packet.comments;
            min_level = packet.min_level;
            max_level = packet.max_level;
            playstyle = packet.playstyle;
            flags = packet.flags;
            unk = packet.unk;
        }

        public PartySettingsPacket(string name, string password, string comments, byte minLevel, byte maxLevel, byte playstyle, PartyFlags flags, ulong unk)
        {
            this.name = name;
            this.password = password;
            this.comments = comments;
            min_level = minLevel;
            max_level = maxLevel;
            this.playstyle = playstyle;
            this.flags = flags;
            this.unk = unk;
        }

        #region implemented abstract members of Packet

        public override byte[] Build()
        {
            var pkt = new PacketWriter();
            pkt.WriteUtf16(name, 0x9789, 0xE3);
            pkt.WriteUtf16(password, 0x9789, 0xE3);
            pkt.WriteUtf16(comments, 0x9789, 0xE3);
            pkt.Write(min_level);
            pkt.Write(max_level);
            pkt.Write(playstyle);
            pkt.WriteEnum(flags);
            pkt.Write(unk);
            return pkt.ToArray();
        }

        public override PacketHeader GetHeader()
        {
            return new PacketHeader(0x0E, 0x0D, PacketFlags.PACKED);
        }

        #endregion
    }
}