using System.Collections.Generic;
using Cirno.Scripts.Enums;
using Godot;
using Godot.Collections;

namespace Cirno.Scripts.Resources.Roguelite;

[GlobalClass]
[Tool]
public partial class RogueliteRoomResource : Resource
{
    [Export] public StringName RoomName { get; set; }
    [Export] public RoomType Type { get; set; } = RoomType.Regular;
    [Export] public StringName ScenePath { get; set; }
    [Export] public Vector2I Size { get; set; } = new(1, 1);

    [Export] public bool StartShrouded { get; set; } = true;
    [Export] public Array<Vector2I> DoorGridPositions { get; set; } = [];

    [Export] public Array<EnemyResource> SpawnableEnemies { get; set; }

    [Export] public DoorDirections DoorDirections { get; set; }

    public bool HasDoors(DoorDirections required) => (DoorDirections & required) == required;

    public override string ToString()
    {
        return $"{RoomName} {Type} {Size.X}x{Size.Y}";
    }

    public List<Vector2I> GetRoomOffsets(Vector2I gridPosition, Direction side)
    {
        List<Vector2I> offsets = [];

        switch (side)
        {
            case Direction.Down:
                for (int i = 0; i < Size.X; i++)
                    offsets.Add(new Vector2I(gridPosition.X - i, gridPosition.Y));
                break;

            case Direction.Up:
                for (int i = 0; i < Size.X; i++)
                    offsets.Add(new Vector2I(gridPosition.X - i, gridPosition.Y + (Size.Y - 1)));
                break;

            case Direction.Right:
                for (int i = 0; i < Size.Y; i++)
                    offsets.Add(new Vector2I(gridPosition.X, gridPosition.Y - i));
                break;

            case Direction.Left:
                for (int i = 0; i < Size.Y; i++)
                    offsets.Add(new Vector2I(gridPosition.X - (Size.X - 1), gridPosition.Y - i));
                break;
        }

        return offsets;
    }
}