/*
<copyright file="BGBoltSetLocale.cs" company="BansheeGz">
    Copyright (c) 2018-2021 All Rights Reserved
</copyright>
*/

using Bolt;
using Ludiq;
using UnityEngine;

namespace BansheeGz.BGDatabase
{

    /// <summary>
    /// Set current locale for localization addon
    /// </summary>
    [UnitCategory("BansheeGz")]
    public class BGBoltSetLocale : Unit
    {
        [DoNotSerialize] public ControlInput _in;
        [DoNotSerialize] public ControlOutput _out;

        [DoNotSerialize] public ValueInput locale;

        protected override void Definition()
        {
            _in = ControlInput("_in", Enter);
            _out = ControlOutput("_out");
            Succession(_in, _out);

            locale = ValueInput("Locale", "");
        }

        private ControlOutput Enter(Flow flow)
        {
            var localeName = flow.GetValue<string>(locale);
            if(string.IsNullOrEmpty(localeName)) Debug.Log("BGBoltSetLocale: can not change locale, cause parameter locale is not set");
            else
            {
                BGRepo.I.Addons.Get<BGAddonLocalization>().CurrentLocale = localeName;
            }
            return _out;
        }
    }
}