using CareFusion.Mosaic.Interfaces.Converters;
using CareFusion.Mosaic.Interfaces.Messages.Stock;
using StorageSystem.Simulator.Interfaces;
using System.Collections.Generic;

namespace StorageSystem.Simulator.Cores.StockUpdateHandler;

internal abstract class StockUpdateHandlerBase : IStockUpdateRequestHandler
{
    private readonly List<IConverterStream> _converterStreams;

    public StockUpdateHandlerBase(List<IConverterStream> converterStreams)
    {
        _converterStreams = converterStreams;
    }
    public void Handle(StockUpdateRequest request)
    {
        var response = new StockUpdateResponse();
        response.AdoptHeader(request);

        FillResponse(request, response);


        foreach (var converterStream in _converterStreams)
        {
            converterStream.Write(response);
        }
    }

    protected abstract void FillResponse(StockUpdateRequest request, StockUpdateResponse response);
}