using System.Collections.Generic;
using System.Linq;
using Cirno.Scripts.Activables;
using Cirno.Scripts.Actors;
using Cirno.Scripts.Resources.Loot;
using Cirno.Scripts.Resources.Roguelite;
using Cirno.Scripts.Utils;
using Godot;
using Godot.Collections;

namespace Cirno.Scripts.Resources;

[GlobalClass]
public partial class RogueliteMapTheme : Resource
{
    [ExportCategory("Dimensions")]
    [Export] public Vector2I TileSize { get; set; } = new Vector2I(16, 16);
    [Export] public Vector2I RoomSizeInTiles { get; set; } = new Vector2I(20, 10);
    
    [ExportGroup("Prefabs")]
    [Export] public PackedScene HorizontalDoorPrefab { get; set; }
    [Export] public PackedScene HorizontalNorthWallPrefab { get; set; }
    [Export] public PackedScene HorizontalSouthWallPrefab { get; set; }
    [Export] public PackedScene VerticalDoorPrefab { get; set; } 
    [Export] public PackedScene VerticalWallPrefab { get; set; }
    [Export] public PackedScene VerticalSecretDoorPrefab { get; set; }
    [Export] public PackedScene DoorLockPrefab { get; set; }
    [Export] public PackedScene KeyCardPrefab { get; set; }
    [Export] public PackedScene ChestPrefab { get; set; }
    [Export] public PackedScene VendingMachinePrefab { get; set; }
    [Export] public Array<PackedScene> KeyCardsPrefabs { get; set; }
    [Export] public PackedScene ShroudPrefab { get; set; }
    [Export] public LootItem PointItemResource { get; set; }
    
    [Export] public PackedScene TeleporterPrefab { get; set; }
    [Export] public PackedScene LevelTeleporterPrefab { get; set; }
    [Export] public StringName LevelTeleporterDestinationPath { get; set; }
    
    
    [ExportGroup("Chances")]
    [Export] public double ChestChance { get; set; }
    [Export] public float EnemyDropChance { get; set; }
    [Export] public LootTable ChestLootTable { get; set; }
    [Export] public LootTable ShopLootTable { get; set; }
    [Export] public LootTable EnemiesLootTable { get; set; }
    [Export] public LootTable WeaponsLootTable { get; set; }
    
    [ExportCategory("Rooms")]
    [Export] public Array<RogueliteRoomResource> Rooms { get; set; }

    [ExportCategory("Floors")]
    [Export] public Array<RogueliteFloorResource> Floors { get; set; } = [];
    
    [ExportCategory("Loot Counts")] public int MaxChestLoot { get; set; } = 100;
    
    public Queue<LootItem> ChestLootQueue { get; private set; }

    public Queue<LootItem> MakeChestLootQueue()
    {
        ChestLootQueue = new Queue<LootItem>().EnqueueRange(ChestLootTable.Items.ToList().Shuffle(MaxChestLoot));

        return ChestLootQueue;
    }

    public List<TeleporterMarker> TeleportersList { get; set; } = [];
    
}