using Ping9719.WpfEx.Mvvm;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using WCS.Model;
using WCS.Model.ApiModel.Home;
using WCS.Model.ApiModel.StoreInfo;
using 智慧物流软件系统.Tool;

namespace 智慧物流软件系统.ViewModel
{
    public class ShelfInfoAddOrUpdateViewModel : BindableBase
    {
        #region Property 属性
        public ShelfInfoAddOrUpdateViewModel()
        {
            ShelfTypeItems = GetBaseData.GetShelfType();
            if (ShelfTypeItems != null && ShelfTypeItems.Count > 0)
                SelectedShelfTypeItem = ShelfTypeItems.First();
        }

        public void SetValues(ShelfInfoModel shelfInfoModel)
        {
            if (shelfInfoModel == null)
            {
                shelfInfoModel = new ShelfInfoModel();
            }
            ShelfId = shelfInfoModel.Id;

            var item = ShelfTypeItems.FirstOrDefault(t => t.Id == shelfInfoModel.ShelfTypeId);
            if (item != null)
            {
                SelectedShelfTypeItem = item;
            }
            ShelfCode = shelfInfoModel.ShelfCode;
            ShelfSize = shelfInfoModel.ShelfSize;
            Remark = shelfInfoModel.Remark;
            IsEnable = shelfInfoModel.IsEnable;

        }

        public ShelfInfoModel GetValues()
        {
            return new ShelfInfoModel()
            {
                Id = ShelfId,
                ShelfTypeId = SelectedShelfTypeItem.Id,
                ShelfTypeName = SelectedShelfTypeItem.ShelfTypeName,
                ShelfCode = ShelfCode,
                ShelfSize = ShelfSize,
                Remark = Remark,
                IsEnable = IsEnable,
            };
        }

        private List<ShelfTypeModel> shelfTypeItems;
        public List<ShelfTypeModel> ShelfTypeItems
        {
            get { return shelfTypeItems; }
            set
            {
                SetProperty(ref shelfTypeItems, value);
            }
        }

        private ShelfTypeModel selectedShelfTypeItem;
        public ShelfTypeModel SelectedShelfTypeItem
        {
            get { return selectedShelfTypeItem; }
            set
            {
                SetProperty(ref selectedShelfTypeItem, value);
            }
        }

        private int shelfId;
        public int ShelfId
        {
            get { return shelfId; }
            set
            {
                SetProperty(ref shelfId, value);
            }
        }

        private string shelfCode;
        public string ShelfCode
        {
            get { return shelfCode; }
            set
            {
                SetProperty(ref shelfCode, value);
            }
        }

        private string shelfSize;
        public string ShelfSize
        {
            get { return shelfSize; }
            set
            {
                SetProperty(ref shelfSize, value);
            }
        }

        private string remark;
        public string Remark
        {
            get { return remark; }
            set
            {
                SetProperty(ref remark, value);
            }
        }

        private bool isEnable;
        public bool IsEnable
        {
            get { return isEnable; }
            set
            {
                SetProperty(ref isEnable, value);
            }
        }
        #endregion
    }
}
