using EVCB_OCPP.Domain;
using EVCB_OCPP.Packet.Messages.SubTypes;
using EVCB_OCPP.WSServer.Dto;
using System;
using System.Linq;
using System.Threading.Tasks;

namespace EVCB_OCPP.WSServer.Service
{

    public interface IBusinessService
    {
        Task<IdTagInfo> Authorize(string chargeBoxId, string idTag);

        Task NotifyFaultStatus(ErrorDetails details);

        Task NotifyConnectorUnplugged(string chargeBoxId,string transactionId,string timestamp);

    }

    static public class BusinessServiceFactory
    {

        static public IBusinessService CreateBusinessService(string customerId)
        {
            bool isCallOut = false;
            using (var db = new MainDBContext())
            {
                isCallOut = db.Customer.Where(x => x.Id == new Guid(customerId)).Select(x => x.CallPartnerApiOnSchedule).SingleOrDefault();
            }

            return isCallOut ? new OuterBusinessService(customerId) : (IBusinessService)new LocalBusinessService(customerId);
        }

    }
}
