using Sirenix.OdinInspector;
using UnityEditor;
using UnityEngine;
using VOID.Generic.Dict;
using VOID.ScriptableObjects.Affiliation;

namespace VOID.Editor.EditorWindow.Affiliation
{
    public record AffiliationEditorConflict
    {
        [ReadOnly]
        [HorizontalGroup("faction1")]
        public Faction faction1;
        
        [ReadOnly]
        [ShowInInspector]
        [HideLabel]
        [HorizontalGroup("faction1")]
        public string faction1Attitude => faction1.GetAttitudeFor(faction2).ToString();
        
        [ReadOnly]
        [HorizontalGroup("faction2")]
        public Faction faction2;
        
        [ReadOnly]
        [ShowInInspector]
        [HideLabel]
        [HorizontalGroup("faction2")]
        public string faction2Attitude => faction2.GetAttitudeFor(faction1).ToString();

        [GUIColor(nameof(GetResolveColor))]
        [InlineButton(nameof(Resolve))]
        public AttitudeType newAttitude;

        private bool _resolved;

        private void Resolve()
        {
            faction1.factionAttitudes[faction2] = newAttitude;
            faction2.factionAttitudes[faction1] = newAttitude;
            _resolved = true;
            
            EditorUtility.SetDirty(faction1);
            EditorUtility.SetDirty(faction2);
            AssetDatabase.SaveAssets();
        }

        private Color GetResolveColor() => _resolved ? Color.green : Color.red;

    }
}