using UnityEngine;

namespace Minesweeper.Config
{
    [CreateAssetMenu(fileName = "MinesweeperUiConfig", menuName = "Minesweeper/UI Config")]
    public sealed class MinesweeperUiConfig : ScriptableObject
    {
        public const float DefaultReferenceCellSize = 100f;
        public const float DefaultBoardPaddingRatio = 0.15f;
        public const float DefaultGridSpacingRatio = 0.02f;
        public const float DefaultMinimumCellSize = 8f;

        [field: SerializeField] public Sprite SmileSprite { get; private set; }
        [field: SerializeField] public Sprite SurprisedSprite { get; private set; }
        [field: SerializeField] public Sprite CoolSprite { get; private set; }
        [field: SerializeField] public Sprite DeadSprite { get; private set; }
        [field: SerializeField] public GameObject CellButtonPrefab { get; private set; }
        [field: SerializeField] public Sprite MineSprite { get; private set; }
        [field: SerializeField] public Sprite FlagSprite { get; private set; }
        [field: SerializeField] public Color ClosedCellColor { get; private set; } = Color.gray;
        [field: SerializeField] public Color OpenedCellColor { get; private set; } = Color.white;
        [SerializeField] private Color defaultTextColor = Color.black;
        [SerializeField] private Color oneMineTextColor = Color.blue;
        [SerializeField] private Color twoMineTextColor = Color.green;
        [SerializeField] private Color threeMineTextColor = Color.red;
        [SerializeField] private Color fourMineTextColor = new Color(0f, 0f, 0.5f, 1f);
        [SerializeField] private Color fiveMineTextColor = new Color(0.5f, 0f, 0f, 1f);
        [SerializeField] private Color sixMineTextColor = Color.cyan;
        [SerializeField] private Color sevenMineTextColor = Color.black;
        [SerializeField] private Color eightMineTextColor = Color.gray;
        [field: SerializeField, Min(DefaultMinimumCellSize)] public float ReferenceCellSize { get; private set; } = DefaultReferenceCellSize;
        [field: SerializeField, Min(0f)] public float BoardPaddingRatio { get; private set; } = DefaultBoardPaddingRatio;
        [field: SerializeField, Min(0f)] public float GridSpacingRatio { get; private set; } = DefaultGridSpacingRatio;
        [field: SerializeField, Min(DefaultMinimumCellSize)] public float MinimumCellSize { get; private set; } = DefaultMinimumCellSize;

        public Sprite GetSmileSprite(SmileFaceState state)
        {
            switch (state)
            {
                case SmileFaceState.Surprised:
                    return SurprisedSprite != null ? SurprisedSprite : SmileSprite;
                case SmileFaceState.Cool:
                    return CoolSprite != null ? CoolSprite : SmileSprite;
                case SmileFaceState.Dead:
                    return DeadSprite != null ? DeadSprite : SmileSprite;
                default:
                    return SmileSprite;
            }
        }

        public Color GetNumberTextColor(int neighborMines)
        {
            switch (neighborMines)
            {
                case 1:
                    return oneMineTextColor;
                case 2:
                    return twoMineTextColor;
                case 3:
                    return threeMineTextColor;
                case 4:
                    return fourMineTextColor;
                case 5:
                    return fiveMineTextColor;
                case 6:
                    return sixMineTextColor;
                case 7:
                    return sevenMineTextColor;
                case 8:
                    return eightMineTextColor;
                default:
                    return defaultTextColor;
            }
        }
    }
}
