using EVCB_OCPP.WSServer.Service;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using OCPPServer.Protocol;
using SuperWebSocket.SubProtocol;
using System;
using System.Collections.Generic;

namespace EVCB_OCPP.WSServer.SuperSocket;

public interface IOCPPWSServerFactory
{
    OCPPWSServer Create(IEnumerable<ISubProtocol<ClientData>> subProtocols);
}

public class OCPPWSServerFactory : IOCPPWSServerFactory
{

    public OCPPWSServerFactory(
        IConfiguration configuration,
        IMainDbService mainDbService,
        ILoggerFactory loggerFactory,
        IServiceProvider serviceProvider)
    {
        this.loggerFactory = loggerFactory;
        this.serviceProvider = serviceProvider;
    }
    public OCPPWSServer Create(IEnumerable<ISubProtocol<ClientData>> subProtocols)
    {
        var logger = loggerFactory.CreateLogger<OCPPWSServer>();
        var server = serviceProvider.GetRequiredService<OCPPWSServer>();
        server.RegisterSubProtocol(subProtocols);
        return server;
    }

    private readonly ILoggerFactory loggerFactory;
    private readonly IServiceProvider serviceProvider;
}
