using Model;
using Newtonsoft.Json;
using Prism.Mvvm;
using Prism.Ioc;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace BOB.ViewModels
{
    public class UpdateInfoViewModel : BindableBase
    {
        private List<UpdateInfoModel> _updateList;
        public List<UpdateInfoModel> UpdateList
        {
            get => _updateList;
            set => SetProperty(ref _updateList, value);
        }

        public UpdateInfoViewModel(IContainerProvider containerProvider)
        {
            string path = Path.Combine(SystemConfig.Instance.SystemPath, "UpdateInfo.json");

            if (File.Exists(path))
            {
                try
                {
                    string json = File.ReadAllText(path, Encoding.UTF8);
                    UpdateList = JsonConvert.DeserializeObject<List<UpdateInfoModel>>(json)
                                 ?? new List<UpdateInfoModel>();
                }
                catch (Exception ex)
                {
                    UpdateList = new List<UpdateInfoModel>();
                    Console.WriteLine("读取 UpdateInfo.json 出错: " + ex.Message);
                }
            }
            else
            {
              
                UpdateList = new List<UpdateInfoModel>();
            }
        }
    }
}
