using BBWYB.Client.Models.PackPurchaseTask;
using BBWYB.Client.Models;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using SJ.Controls;
using BBWYB.Client.APIServices;
using BBWYB.Client.Models.APIModel;

namespace BBWYB.Client.Views.PackPurchaseTask
{
    /// <summary>
    /// SetBarCode.xaml 的交互逻辑
    /// </summary>
    public partial class SetBarCodeWindow : BWindow
    {
        public SetBarCodeWindow()
        {
            InitializeComponent();
            BarLabelCheckCommand = new RelayCommand<BarcodeLabelModel>(BarLabelCheck);
        }
        public void LoadData(BarCodeModel barCodeModel, PackPurchaseTaskService PackTaskService)
        {
            BarCodeModel = barCodeModel; packTaskService = PackTaskService;
            this.DataContext = this;
        }

        public BarCodeModel BarCodeModel { get; set; }
        public PackPurchaseTaskService packTaskService { get; set; }
        public Action<BarCodeModel> SaveResult { get; set; }




        private void BButton_Click(object sender, RoutedEventArgs e)
        {
            if (BarCodeModel.LabelModel == BarcodeLabelModel.标准模板)//标准版 判断数据是否异常
            {
                if (string.IsNullOrEmpty(BarCodeModel.ProductNo) || BarCodeModel.ProductNo == "待填写")
                {
                   MessageBox.Show("该SKU无货号信息,将影响条形码打印\r\n请先设置好货号信息或调整打印模板类型");
              
                    return;
                }
            }

            //保存到服务器中   返回id
            var resData = packTaskService.SaveBarCode(new BarCodeRequest
            {
                Brand = BarCodeModel.Brand,
                BrandName = BarCodeModel.BrandName,
                ProductNo = BarCodeModel.ProductNo,
                SkuId = BarCodeModel.SkuId,
                SkuName = BarCodeModel.SkuName,
                LabelModel = BarCodeModel.LabelModel

            });
            if (resData == null || !resData.Success)
            {
                return;
            }

            BarCodeModel.Id = resData.Data;
            if (SaveResult != null)
                SaveResult(BarCodeModel);

            this.Close();
        }

        public ICommand BarLabelCheckCommand { get; set; }
        public void BarLabelCheck(BarcodeLabelModel labelModel)
        {
            if (labelModel == BarcodeLabelModel.标准模板)//标准版 判断数据是否异常
            {
                if (string.IsNullOrEmpty(BarCodeModel.ProductNo) || BarCodeModel.ProductNo == "待填写")
                {
                    MessageBox.Show("该SKU无货号信息,将影响条形码打印\r\n请先设置好货号信息或调整打印模板类型");
          
                }
            }


        }
    }
}