using Microsoft.Extensions.Logging;
using SlnMesnac.Model.AirportApiEntity;
using SlnMesnac.Repository.service;
using SlnMesnac.TouchSocket;
using System;
using System.Collections.Generic;
using System.Text;

namespace SlnMesnac.Business.@base
{
    public class BaseStateRefreshBusiness
    {
        private IAGVStateService _AGVStateService;
        private IManipulatorStateService _ManipulatorStateService;
        private ILogger<BaseStateRefreshBusiness> _logger;
        private static BaseStateRefreshBusiness instance;
        public BaseStateRefreshBusiness(ILogger<BaseStateRefreshBusiness> logger, IAGVStateService agvService, IManipulatorStateService manipulatorStateService)
        {
            _logger = logger;
            _AGVStateService = agvService;
            _ManipulatorStateService = manipulatorStateService;
        }
        public static BaseStateRefreshBusiness GetInstance(ILogger<BaseStateRefreshBusiness> logger, IAGVStateService agvService, IManipulatorStateService manipulatorStateService)
        {
            if (instance == null)
            {
                instance = new BaseStateRefreshBusiness(logger, agvService, manipulatorStateService);
            }
            return instance;
        }

        public bool UpdateAGVStateByResposne(AGVStateRequestEntity request) 
        {
            try
            {
                var response = AirPorthttpClient.AGVStateRequest(request);
                _AGVStateService.UpdateOrAddByResponse(response);
            }
            catch (Exception e) 
            {
                _logger.LogError("Error:" + e);
            }
            return true;
        }

        public bool UpdateManipulatorStateByResposne(ManipulatorStateRequestEntity request)
        {
            try
            {
                var response = AirPorthttpClient.ManipulatorStateRequest(request);
                _ManipulatorStateService.UpdateOrAddByResponse(response);
            }
            catch (Exception e)
            {
                _logger.LogError("Error:" + e);
            }
            return true;
        }
    }
}
