using BBWY.Client.APIServices;
using BBWY.Client.Models;
using BBWY.Controls;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WebSocketSharp;

namespace BBWY.Client.Views.TaskOverTime
{
    /// <summary>
    /// SubmitOverTimeMarkMsgWindow.xaml 的交互逻辑
    /// </summary>
    public partial class SubmitOverTimeMarkMsgWindow : BWindow
    {
        public SubmitOverTimeMarkMsgWindow(OverTimeTaskType overTimeTaskType, long id, string msg, PackTaskService packTaskService, Action reflashWindow)
        {
            InitializeComponent();
            this.OverTimeTaskType = overTimeTaskType;
            this.Id = id;
            MarkMsg = msg;
            this.reflashWindow = reflashWindow;
            this.packTaskService = packTaskService;
            this.DataContext = this;
        }
        Action reflashWindow;
        PackTaskService packTaskService { get; set; }
        /// <summary>
        /// 超时任务类型(待验收 = 2,待打包 = 3,待封箱 = 4, 待落仓 = 8,待转运 = 11,)
        /// </summary>
        public OverTimeTaskType OverTimeTaskType { get; set; }

        /// <summary>
        /// 任务id 或者 封箱id
        /// </summary>
        public long Id { get; set; }
        /// <summary>
        /// 备注信息
        /// </summary>
        public string MarkMsg { get; set; }

        private void BButton_Click(object sender, RoutedEventArgs e)
        {
            if (MarkMsg.IsNullOrEmpty())
            {
                MessageBox.Show("请输入超时原因");
                return;
            }

            var res = packTaskService.SubmitOverTimeMarkMsg(OverTimeTaskType, Id, MarkMsg);
            if (res == null)
            {
                MessageBox.Show("网络异常");
                return;
            }
            if (!res.Success)
            {
                MessageBox.Show(res.Msg);
                return;
            }
            if (reflashWindow != null) reflashWindow();

            App.Current.Dispatcher.Invoke(new Action(() => { this.Close(); }));
           
        }
    }
}