class ExporterImpl implements Exporter {

    public List<File> exportReport(ExportSettings settings, List<Participant> participants, Trip trip,
                                   ResourceResolver resourceResolver, ActivityResolver activityResolver, AmountFactory amountFactory) {

        List<File> filesCreated = new ArrayList<>();

        StringBuilder fileNamePrefix = new StringBuilder(resourceResolver.resolve(R.string.fileExportPrefix))
                .append(FILE_NAME_SEPARATOR)
                .append(ExporterFileNameUtils.clean(trip.getName()));
        StringBuilder timestamp = new StringBuilder(ExporterFileNameUtils.getTimeStamp(resourceResolver.getLocale()));

        HtmlExportCharResolver htmlExportCharResolver = null;
        CsvExportCharResolver csvExportCharResolver = null;
        TxtExportCharResolver txtExportCharResolver = null;

        if (settings.isFormatHtml()) {
            htmlExportCharResolver = new HtmlExportCharResolver();
            htmlExportCharResolver.setLang(resourceResolver.getLocale().getLanguage());
        }
        if (settings.isFormatCsv()) {
            csvExportCharResolver = new CsvExportCharResolver();
        }
        if (settings.isFormatTxt()) {
            txtExportCharResolver = new TxtExportCharResolver();
        }

        if (participants.size() > 1 && settings.isSeparateFilesForIndividuals()) {
            ArrayList<Participant> participantsSubset;
            for (Participant p : participants) {
                participantsSubset = new ArrayList<>(1);
                participantsSubset.add(p);
                createAndWriteFiles(settings,
                        participantsSubset,
                        trip,
                        resourceResolver,
                        fileWriter,
                        filesCreated,
                        fileNamePrefix,
                        timestamp,
                        htmlExportCharResolver,
                        csvExportCharResolver,
                        txtExportCharResolver,
                        amountFactory);
            }
        } else {
            createAndWriteFiles(settings,
                    participants,
                    trip,
                    resourceResolver,
                    fileWriter,
                    filesCreated,
                    fileNamePrefix,
                    timestamp,
                    htmlExportCharResolver,
                    csvExportCharResolver,
                    txtExportCharResolver,
                    amountFactory);
        }

        StreamSender streamSender = new StreamSenderImpl();
        StringBuilder exportSubject = new StringBuilder()
                .append(resourceResolver.resolve(R.string.fileExportEmailSubjectPrefix))
                .append(SPACE)
                .append(trip.getName())
                .append(SPACE)
                .append(timestamp);

        if (activityResolver.getActivity() != null) {
            List<Uri> contentUrisFromFiles = FileUtils.getContentUrisFromFiles(filesCreated, TrickyTripperFileProvider.AUTHORITY);
            if (settings.getOutputChannel() != null) {
                streamSender.sendStream(
                        (Activity) activityResolver.getActivity(),
                        exportSubject.toString(),
                        resourceResolver.resolve(R.string.fileExportEmailContent),
                        contentUrisFromFiles, settings.getOutputChannel());
            }
        }

        return filesCreated;

    }

    public  ExporterImpl(FileWriter fileWriter);

}