using System.Collections.Generic;
using EscapeRoomEngine.Engine.Runtime.Modules;
using EscapeRoomEngine.Engine.Runtime.Utilities;
using JetBrains.Annotations;
using NaughtyAttributes;
using UnityEngine;

namespace EscapeRoomEngine.Engine.Runtime
{
    /// <summary>
    /// An engine theme decides the room size, look and available modules for the engine.
    /// </summary>
    [CreateAssetMenu(menuName = "Engine Theme")]
    public class EngineTheme : ScriptableObject
    {
        #region Size
        
        [BoxGroup("Size")] [Tooltip("The minimum size that should be allowed for rooms.")]
        public Vector2Int minRoomSize;

        [BoxGroup("Size")] [Tooltip("The size of the physical play space available to the engine.")]
        public Vector2Int playSpace;
        
        #endregion

        #region Theme

        [BoxGroup("Theme")] [Required]
        [Tooltip("The tile that rooms are generated from.")]
        public SpaceTile spaceTile;

        [BoxGroup("Theme")]
        [Tooltip("The environment that is placed around every generated room.")]
        public GameObject environment;

        [BoxGroup("Theme")]
        public DynamicColor puzzleColor, solvedColor, activeColor;

        #endregion

        #region Doors
        
        [BoxGroup("Doors")] [Required]
        public DoorModuleDescription spawnDoor;
        
        [BoxGroup("Doors")] [ValidateInput("IsNotEmpty", "At least one exit door type is required.")]
        [Tooltip("The types of exit doors this theme provides. Entrance doors are connected to the exit doors and don't need to be specified here.")]
        public List<DoorModuleDescription> exitDoorTypes;

        #endregion

        #region Puzzles
        
        [BoxGroup("Puzzles")] [MinMaxSlider(0, 24)]
        public Vector2Int puzzleCount;
        
        [BoxGroup("Puzzles")]
        public List<PuzzleModuleDescription> puzzleTypes;

        public PuzzleModuleDescription GetPuzzle(int id) => puzzleTypes.Find(puzzle => puzzle.Id == id);

        #endregion

        [UsedImplicitly]
        private bool IsNotEmpty(List<DoorModuleDescription> modules) => modules.Count > 0;
    }
}