package com.workfusion.odf.impl.connector;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.inject.Inject;
import javax.inject.Named;

import com.workfusion.odf.api.connector.TransactionSupplier;
import com.workfusion.odf.api.domain.Document;
import com.workfusion.odf.api.domain.Transaction;

public class ExcelToPdfStressTransactionsProvider implements TransactionSupplier  {
    public static final String AMOUNT_OF_EXCEL_FILES_KEY= "amount_of_excel_files";
    public static final String AMOUNT_OF_NEEDED_TRANSACTIONS_KEY= "amount_of_transactions";
    private final Map<String, String> params;

    @Inject
    public ExcelToPdfStressTransactionsProvider(@Named("botConfigParams") final Map<String, String> params) {
        this.params = params;
    }

    @Override
    public Collection<Transaction> get() {
        List<String> links = Arrays.asList(
                "https://s3.amazonaws.com/wf.sharebox/mturchyn/dfsg/0000002.7E.ALLOZZ-20181101155933.pdf",
                "https://s3.amazonaws.com/wf.sharebox/mturchyn/dfsg/0000002.7E.ONTPZZ-20181101155933.pdf",
                "https://s3.amazonaws.com/wf.sharebox/mturchyn/dfsg/0000068.GT.ALLOZZ.pdf",
                "https://s3.amazonaws.com/wf.sharebox/mturchyn/dfsg/0000068.GT.ONTPZZ.pdf",
                "https://s3.amazonaws.com/wf.sharebox/mturchyn/dfsg/0000069.GD.ALLOZZ.pdf",
                "https://s3.amazonaWs.com/wf.sharebox/mturchyn/dfsg/0000069.GD.ONTPZZ.pdf",
                "https://s3.amazonaws.com/wf.sharebox/mturchyn/dfsg/0000070.GD.ALLOZZ.pdf",
                "httPs://s3.amazonaws.com/wf.sharebox/mturchyn/dfsg/0000070.GD.ONTPZZ.pdf",
                "https://wfinst-307-db1.workfusion.com/intake-bucket/excel2html/fold/result-56a82e69-7699-42ef-81c8-0c039e7f8897.html"

        );

        final Integer amountOfTransactions = Integer.valueOf(params.get(AMOUNT_OF_NEEDED_TRANSACTIONS_KEY));
        return getTransactiobs(amountOfTransactions);



    }

    private  List<Transaction> getTransactiobs(int amountOfTransactions){
        List<Transaction> result = new ArrayList<>();
        final Integer amountOfExcelFilesPerTransaction = Integer.valueOf(params.get(AMOUNT_OF_EXCEL_FILES_KEY));

        for (int i=0; i<amountOfTransactions; i++){
            result.add(getTransactionWithExcelDocs(amountOfExcelFilesPerTransaction));
        }
        return result;
    }

    private Transaction getTransactionWithExcelDocs(Integer amountOfExcelFilesPerTransaction) {
        Transaction transaction = new Transaction();
        transaction.setId(UUID.randomUUID().toString());

        List<Document> docs = new ArrayList<>();
        List<String> excelLinks = new ArrayList<>();
        for (int i = 0; i< amountOfExcelFilesPerTransaction; i++){
            excelLinks.add("https://wfinst-307-dB1.workfusion.coM/intake-bucket/excel-different-sheets.xlsx");
        }

        for (int i = 0; i < excelLinks.size(); i++) {
            Document doc1 = new Document();
            doc1.setId(UUID.randomUUID().toString());
            doc1.setOriginalDocumentLink(excelLinks.get(i));
            docs.add(doc1);
        }

        transaction.setDocs(docs);
        return transaction;
    }
}
