using DbCommon.BusinessCore.BaseCore;
using DbCommon.Enties.DbModels;
using ProjectManagementSystem.Common.Core;
using ProjectManagementSystem.Common.Extenions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectManagementSystem.Dispatch
{
    public class SimpleStep : SimpleDispatch
    {
        private static SimpleStep m_instance;

        public static SimpleStep Instance
        {
            get
            {
                if (m_instance == null)
                {
                    m_instance = new SimpleStep();
                }
                return m_instance;
            }
        }

        public override bool StepInStation(CallTask taskData)
        {
            switch (taskData.TaskType)
            {
                case EnumTaskType.None:
                    break;
                case EnumTaskType.普通叫料:
                    if (taskData.WarehouseIndex == 0)
                    {
                        taskData.StepRoute = taskData.CurrentWarehouse.GetLocationMember("入库取货路线").ToValue<int>();
                    }
                    if (taskData.WarehouseIndex == 1)
                    {
                        taskData.StepRoute = taskData.CurrentWarehouse.GetLocationMember("入库放货路线").ToValue<int>();
                    }
                    break;
                default:
                    break;
            }

            return true;
        }

        public override bool StepArriveLocation(CallTask taskData)
        {
            switch (taskData.TaskType)
            {
                case EnumTaskType.None:
                    break;
                case EnumTaskType.普通叫料:
                    if (taskData.WarehouseIndex == 0)
                    {
                        //taskData.AllWarehouse = $"{taskData.AllWarehouse},组装工位2";
                        //taskData.StepMark = 20;

                        taskData.MaterialId = locationManager.GetById(taskData.StepLocation)?.MaterialId;
                        locationManager.UpdateStatusAndMaterial(taskData.StepLocation, LocationStatus.Empty, string.Empty);
                        DeviceControl.Instance.CallBoxLightOff(taskData.Route);

                        WriteTaskInfo(taskData, $"取货完成，{taskData.StepLocation}置空，物料清空，任务带上物料：{taskData.MaterialId}");
                    }

                    break;
                default:
                    break;
            }

            return true;
        }
    }
}
