﻿using RecklassRekkids.Core.ContractsFileLoading;
using RecklassRekkids.Core.OutputFormatting;
using RecklassRekkids.Core.Queries;
using RecklassRekkids.Core.Utilities;

namespace RecklassRekkids.Core
{
   public class DummyIocContainer
   {
      private readonly ContractStore contractStore;
      private readonly EnglishDateFormatter dateFormatter;
      private readonly PartnerDateQuery partnerDateQuery;

      private readonly TextFileReader textFileReader;
      private readonly UsageConverter usageConverter;

      public DummyIocContainer()
      {
         textFileReader = new TextFileReader();
         usageConverter = new UsageConverter();
         dateFormatter = new EnglishDateFormatter();

         contractStore = new ContractStore();
         partnerDateQuery = new PartnerDateQuery(contractStore);
      }

      public GlobalRightsManagementPlatformLoader CreateLoader(char fieldDelimiter, char usageDelimiter)
      {
         ILineParser<MusicContract> musicContractLineParser = new MusicContractLineParser(usageConverter, dateFormatter, fieldDelimiter, usageDelimiter);
         var musicContractFileParser = new ContractFileParser<MusicContract>(musicContractLineParser);
         var musicContractFileLoader = new ContractFileLoader<MusicContract>(textFileReader, musicContractFileParser);

         ILineParser<DistributionPartnerContract> distributionPartnerContractLineParser = new DistributionPartnerContractLineParser(usageConverter, fieldDelimiter);
         var distributionPartnerContractFileParser = new ContractFileParser<DistributionPartnerContract>(distributionPartnerContractLineParser);
         var distributionPartnerContractFileLoader = new ContractFileLoader<DistributionPartnerContract>(textFileReader, distributionPartnerContractFileParser);

         return new GlobalRightsManagementPlatformLoader(musicContractFileLoader, distributionPartnerContractFileLoader, contractStore);
      }

      public GlobalRightsManagementPlatformQueryer CreateQueryer(char fieldDelimiter)
      {
         var outputFormatter = new DelimitedFormatter(usageConverter, fieldDelimiter);
         return new GlobalRightsManagementPlatformQueryer(partnerDateQuery, outputFormatter);
      }

      public PartnerDateQueryParameterParser CreateParameterParser()
      {
         return new PartnerDateQueryParameterParser(dateFormatter);
      }
   }
}