using DbCommon.BusinessCore.BaseCore;
using DbCommon.Enties.DbModels;
using DbCommon.Extenions;
using PmsSecondaryPackaging.Interface.Model.Carrier;
using PmsSecondaryPackaging.Interface.Model.StepBook;
using PmsSecondaryPackaging.Interface.Model.TaskBook;
using PmsSecondaryPackaging.TaskManager.TaskBookBehavior;
using ProjectManagementSystem.Common.Log;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectManagementSystem.TaskBookEvent
{
    public class TaskBookBehavior_63003 : BaseTaskBookBehavior
    {
        LocationPropertyManager locationManager = new LocationPropertyManager();
        MaterialBindingManager materialBindingManager = new MaterialBindingManager();

        public TaskBookBehavior_63003() : base(63003)
        {
        }

        public override bool TaskBookOperator(TaskDetailInfoModel taskDetailInfo, List<StepDetailInfoModel> taskStepInfoList, CarrierInfoModel carrierInfo)
        {
            try
            {
                var stepInfo = TaskBookRegister.GetCurrentStepDetailInfo(taskDetailInfo, taskStepInfoList);

                var materialBinding = materialBindingManager.GetById(taskDetailInfo.TaskID);
                var data = locationManager.QueryData(stepInfo.WareHouseID);

                data.MaterialBarcode = materialBinding.MaterialBarcode;
                data.MaterialId = materialBinding.MaterialID;
                data.MaterialName = materialBinding.MaterialName;
                data.MaterialNumber = materialBinding.MaterialNumber.ToString();
                data.MaterialWeight = materialBinding.MaterialWeight.ToString();
                data.BatchNumber = materialBinding.BatchNumber;

                data.Status = LocationStatus.Filled;
                bool result = locationManager.Update(data);
                if(result)
                {
                    materialBindingManager.Delete(materialBinding);
                }
                TaskBookRegister.Log(taskDetailInfo, stepInfo, $"库位放货，操作结果:{result}");
                return result;
            }
            catch (Exception ex)
            {
                TaskBookRegister.LogException(ex);
            }
            return false;
        }
    }
}
