using PSO2SERVER.Database;
using PSO2SERVER.Models;
using PSO2SERVER.Protocol.Packets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PSO2SERVER.Party
{
    public class Party
    {
        public enum PartyColor : byte
        {
            Red,
            Green,
            Yellow,
            Blue,
        }

        public string name;
        private List<Client> members;
        private Client host;
        public Quest currentQuest;

        public Party(string name, Client host)
        {
            this.name = name;
            this.host = host;
            this.members = new List<Client>();
            addClientToParty(host);
        }

        public void addClientToParty(Client c)
        {
            if (members.Count < 1)
            {
                c.SendPacket(new PartyInitPacket(new Character[1] { c.Character }));
            }
            else
            {
                // ???
            }
            members.Add(c);
            c.currentParty = this;
        }

        public void removeClientFromParty(Client c)
        {
            if(!members.Contains(c))
            {
                Logger.WriteWarning("[PTY] Client {0} was trying to be removed from {1}, but he was never in {1}!", c._account.Username, name);
                return;
            }

            members.Remove(c);
            //TODO do stuff like send the "remove from party" packet.
        }

        public bool hasClientInParty(Client c)
        {
            return members.Contains(c);
        }

        public Client getPartyHost()
        {
            return host;
        }

        public int getSize()
        {
            return members.Count;
        }

        public List<Client> getMembers()
        {
            return members;
        }
    }

    [Flags]
    public enum PartyFlags : byte
    {
        /// Is the party only for friends.
        FRIENDS_ONLY = 1 << 0, // 0x01
        /// Is the party only for alliance members.
        ALLIANCE_ONLY = 1 << 1, // 0x02
        /// Limit multiplayer requests from other parties.
        LIMIT_OTHERS = 1 << 2, // 0x04
        /// Is the party only for a single run.
        SINGLE_RUN = 1 << 3, // 0x08
        /// Is the party actively looking for members.
        OPEN = 1 << 4, // 0x10
        /// Is the party voice chat focused.
        VC_FOCUS = 1 << 6 // 0x40
    }
}
