using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using PSO2SERVER.Models;
using PSO2SERVER.Object;
using PSO2SERVER.Protocol.Packets;
using PSO2SERVER.Zone;
using static PSO2SERVER.Protocol.Handlers.TeleportCasinoToLobby;

namespace PSO2SERVER.Protocol.Handlers
{
    [PacketHandlerAttr(0x03, 0x38)]
    public class TeleportBridgeToLobby : PacketHandler
    {
        /// (0x03, 0x38) Move Bridge -> Lobby. TODO
        public struct BridgeToLobbyPacket
        {
            public uint unk1;
            public uint unk2;
            public uint unk3;
            public uint zone_id;
            public uint unk4;
        }

        public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
        {
            var reader = new PacketReader(data);
            var pkt = reader.ReadStruct<BridgeToLobbyPacket>();

            Logger.Write($"unk1 {pkt.unk1} unk2 {pkt.unk2} unk3 {pkt.unk3} zone_id {pkt.zone_id} unk4 {pkt.unk4}");

            if(pkt.unk3 != 0x10)
            {
                Logger.WriteWarning("[WRN] Packet 0x3 0x34's first value was not 0x10! Investigate.");
            }

            PSOLocation destination;
            if(pkt.zone_id == 0) // Gate area
            {
                destination = new PSOLocation(0f, 1f, 0f, 0f, -0.22f, 2.4f, 198.75f);
            }
            else // Shop area
            {
                destination = new PSOLocation(0f, 1f, 0f, 20f, 0.20f, 1.23f, -175.25f);
            }
            Map lobbyMap = ZoneManager.Instance.MapFromInstance("lobby", "lobby");
            lobbyMap.SpawnClient(context, destination, "lobby");
            
        }
    }
}
