package ru.micord.ervu.journal.mapper;

import java.sql.Timestamp;

import ervu_lkrp_ul.ervu_lkrp_ul.db_beans.public_.tables.records.InteractionLogRecord;
import ru.micord.ervu.journal.JournalDto;
import ru.micord.ervu.journal.JournalFileInfo;
import ru.micord.ervu.journal.SenderInfo;

import static ru.micord.ervu.util.StringUtils.convertToFio;

public class JournalDtoMapper {

  public static JournalDto mapToJournalDto(JournalFileInfo journalFileInfo) {
    SenderInfo senderInfo = journalFileInfo.getSenderInfo();
    return new JournalDto()
        .setFileId(journalFileInfo.getFileId())
        .setDepartureDateTime(Timestamp.valueOf(journalFileInfo.getDepartureDateTime()).toString())
        .setFileName(journalFileInfo.getFileName())
        .setFilePatternCode(journalFileInfo.getFilePatternCode())
        .setSenderFio(convertToFio(senderInfo.getFirstName(), senderInfo.getMiddleName(),
                senderInfo.getLastName()
            )
        )
        .setStatus(journalFileInfo.getFileStatus().getStatus())
        .setFilesSentCount(journalFileInfo.getRowsCount())
        .setAcceptedFilesCount(journalFileInfo.getRowsSuccess());
  }

  public static JournalDto mapToJournalDto(InteractionLogRecord record) {
    return new JournalDto()
        .setDepartureDateTime(record.getSentDate().toString())
        .setFileName(record.getFileName())
        .setFilePatternCode(Integer.valueOf(record.getForm()))
        .setSenderFio(record.getSender())
        .setStatus(record.getStatus())
        .setFilesSentCount(record.getRecordsSent())
        .setAcceptedFilesCount(record.getRecordsAccepted())
        .setFileId(record.getFileId());
  }
}
