using UnityEngine;
using System.Collections.Generic;

namespace MaskShop
{
    /// <summary>
    /// Type of decoration that determines its behavior
    /// </summary>
    public enum DecorationType
    {
        MoodDecoration,      // Contributes to mood (eyes, mouth, etc.)
        GimmickDecoration,   // Adds special features (horns, flowers, etc.)
        PaletteDecoration    // Adds color/material
    }

    /// <summary>
    /// Represents a decoration item that can be applied to masks
    /// </summary>
    [CreateAssetMenu(fileName = "New Decoration", menuName = "Mask Shop/Decoration Item")]
    public class DecorationItem : ScriptableObject
    {
        [Header("Decoration Information")]
        [SerializeField] private string decorationName;
        [SerializeField, TextArea] private string description;
        [SerializeField] private Sprite icon;

        [Header("Type and Properties")]
        [SerializeField] private DecorationType decorationType;
        [SerializeField] private GameObject decorationPrefab;

        [Header("Mood Contribution (if applicable)")]
        [SerializeField] private List<MaskMood> contributesToMoods = new List<MaskMood>();

        [Header("Gimmick Contribution (if applicable)")]
        [SerializeField] private MaskGimmick contributesToGimmick;

        [Header("Palette Contribution (if applicable)")]
        [SerializeField] private MaskPalette contributesToPalette;
        [SerializeField] private Material paletteMaterial; // For color decorations

        [Header("QTE Settings")]
        [SerializeField] private QTEType qteType = QTEType.TimingBar;
        [SerializeField, Range(0.5f, 3f)] private float qteDifficulty = 1f;

        [Header("Placement")]
        [Tooltip("Which slot in the mask this decoration should attach to")]
        [SerializeField] private string targetSlotName;
        [SerializeField] private Vector3 defaultPosition = Vector3.zero;
        [SerializeField] private Vector3 defaultRotation = Vector3.zero;
        [SerializeField] private Vector3 defaultScale = Vector3.one;

        [Header("Unlock Requirements")]
        [SerializeField] private int requiredLevel = 1;
        [SerializeField] private bool isUnlocked = true;

        // Properties
        public string DecorationName => decorationName;
        public string Description => description;
        public Sprite Icon => icon;
        public DecorationType Type => decorationType;
        public GameObject DecorationPrefab => decorationPrefab;
        public List<MaskMood> ContributesToMoods => contributesToMoods;
        public MaskGimmick ContributesToGimmick => contributesToGimmick;
        public MaskPalette ContributesToPalette => contributesToPalette;
        public Material PaletteMaterial => paletteMaterial;
        public QTEType QteType => qteType;
        public float QteDifficulty => qteDifficulty;
        public string TargetSlotName => targetSlotName;
        public Vector3 DefaultPosition => defaultPosition;
        public Vector3 DefaultRotation => defaultRotation;
        public Vector3 DefaultScale => defaultScale;
        public int RequiredLevel => requiredLevel;
        public bool IsUnlocked => isUnlocked;

        /// <summary>
        /// Checks if this decoration contributes to the requested mood
        /// </summary>
        public bool ContributesToMood(MaskMood requestedMood)
        {
            if (requestedMood == null) return false;
            return contributesToMoods.Contains(requestedMood);
        }

        /// <summary>
        /// Checks if this decoration matches any request parameter
        /// </summary>
        public bool MatchesRequest(MaskRequest request)
        {
            // Check mood contribution
            if (request.HasMood() && ContributesToMood(request.mood))
                return true;

            // Check gimmick contribution
            if (request.HasGimmick() && contributesToGimmick == request.gimmick)
                return true;

            // Check palette contribution
            if (request.HasPalette() && contributesToPalette == request.palette)
                return true;

            return false;
        }

        /// <summary>
        /// Unlocks this decoration
        /// </summary>
        public void Unlock()
        {
            isUnlocked = true;
        }
    }
}