using Godot;
using System;
using System.Collections.Generic;

public partial class PredictiveCollisions : Node {
    [Export]
    public ShapeCast2D BottomLeft { get; set; }
    [Export]
    public ShapeCast2D BottomRight { get; set; }
    [Export]
    public ShapeCast2D TopLeft { get; set; }
    [Export]
    public ShapeCast2D TopRight { get; set; }

    [Flags]
    public enum Location {
        BottomRight = 0b01,
        TopRight = 0b11,
        TopLeft = 0b10,
        BottomLeft = 0b00
    }


    public Godot.Collections.Array Cast(Location location) {
        GetShapeCast(location).ForceShapecastUpdate();
        return GetShapeCast(location).CollisionResult;
    }

    public bool AnyHit(Location location)
        => (Cast(location)?.Count ?? -1) > 0;

    public Godot.Collections.Array GetLastCastHits(Location location) {
        return GetShapeCast(location).CollisionResult;
    }

    public ShapeCast2D GetShapeCast(Location location) => location switch {
        Location.BottomLeft => BottomLeft,
        Location.BottomRight => BottomRight,
        Location.TopLeft => TopLeft,
        Location.TopRight => TopRight,
        _ => throw new Exception("Invalid location")
    };
}
