using BPA.Model.Recipe;
using BPA.SingleDevice.Interface;
using BPA.SingleDevice.Services;

namespace BPA.SingleDevice.ViewModel
{
    public class RecipeStatusViewModel : NotifyBase
    {
        private readonly IProcessControl process;
        private ObservableCollection<RecipeData> currentRecipes;

        public RecipeStatusViewModel(IProcessControl process, ILogService logService)
        {
            this.process = process;

            CurrentRecipes = process.CurrentRecipes;

            RemoveCommand = new((obj) =>
            {
                if (obj is not null && obj is RecipeData recipe)
                {
                    if (MessageBoxR.ConfirmGlobal("是否取消配方？") == System.Windows.MessageBoxResult.Yes)
                    {
                        //process.CurrentRecipes.Remove(recipe);
                        var result = ActionManage.GetInstance.Send<RecipeData, bool>(recipe, "RemoveRecipe");
                        if (result != null && result.IsSuccess && result.Content == true)
                        {
                            Message.SuccessGlobal("取消配方成功。");
                            logService.LogUserInfo($"从队列中取消一个配方【{recipe.Name}】。");
                        }
                        else
                        {
                            Message.ErrorGlobal("取消配方失败。");
                        }
                    }
                }
            });
        }

        /// <summary>当前正在制作的配方</summary>
        public ObservableCollection<RecipeData> CurrentRecipes
        { get => currentRecipes; set { currentRecipes = value; OnPropertyChanged(); } }

        public BPARelayCommand<object> RemoveCommand { get; set; }
    }
}