using Khd.Core.Domain.Models;
using Khd.Core.Wpf.dto;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;

namespace Khd.Core.Wpf.myConverter
{
    [ValueConversion(typeof(int), typeof(string))]
    public class AgvTaskStatusConverter : IValueConverter
    {
        private readonly Dictionary<long?, Dictionary<int?, string>> dic = new()
        {
            {2,
                new Dictionary<int?,string>(){
                    {-1,"人工创建" },
                    {0,"未下发" },
                    {1,"已下发" },
                    {2,"任务开始" },
                    {3,"已到起始地" },
                    {4,"起始地继续任务" },
                    {5,"已到目的地" },
                    {6,"任务结束" },
                }
            },
            {
                4,
                new Dictionary<int?, string>(){
                    {-1,"人工创建" },
                    {0,"未下发" },
                    {1,"已下发" },
                    {2,"已开始" },
                    {3,"已到达起始地" },
                    {4,"起始地继续任务" },
                    {5,"已到达目的地" },
                    {6,"任务结束" }
                }
            },
            {
                  5,
                new Dictionary<int?, string>(){
                    {-1,"人工创建" },
                    {0,"未下发" },
                    {1,"已下发" },
                    {2,"已开始" },
                    {3,"已到达起始地" },
                    {4,"起始地继续任务" },
                    {5,"已到达目的地" },
                    {6,"目的地等待完成" },
                    {7,"目的地捡料完成" },
                    {8,"任务结束" }
                }
            },
            {
                  6,
                new Dictionary<int?, string>(){
                    {-1,"人工创建" },
                    {0,"未下发" },
                    {1,"已下发" },
                    {2,"已开始" },
                    {3,"已到达起始地" },
                    {4,"起始地继续任务" },
                    {5,"已到达目的地" },
                    {6,"任务结束" }
                }
            },
            {
                  11,
                new Dictionary<int?, string>(){
                    {-1,"人工创建" },
                    {0,"未下发" },
                    {1,"已下发" },
                    {2,"已开始" },
                    {3,"已到达起始地" },
                    {4,"起始地继续任务" },
                    {5,"已到达目的地" },
                    {6,"任务结束" }
                }
            }
        };
        private DataGridRow GetDataGridRow(DependencyObject dependencyObject)
        {
            if (dependencyObject == null)
                return null;

            var dataGridRow = dependencyObject as DataGridRow;
            if (dataGridRow != null)
                return dataGridRow;

            return GetDataGridRow(VisualTreeHelper.GetParent(dependencyObject));
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is taskModel wcsTask)
            {
                BaseEquip baseEquip = SystemData.BaseEquip.First(t => t.objid == wcsTask.nextPointId);
                if (dic.TryGetValue(baseEquip.equipType, out var taskStatusDic))
                {
                    if (taskStatusDic.TryGetValue(wcsTask.taskStatus, out var taskStatus))
                    {
                        return taskStatus;
                    }
                }
            }
            return "未知";
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }
    }
}
