package ru.ibs.socrates.confexporter.service.content.service.impl;

import java.time.OffsetDateTime;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import ru.ibs.socrates.confexporter.api.dto.ProjectContentResponse;
import ru.ibs.socrates.confexporter.api.dto.ProjectResponse;
import ru.ibs.socrates.confexporter.dao.service.MessageDaoService;
import ru.ibs.socrates.confexporter.dao.service.ProjectDaoService;
import ru.ibs.socrates.confexporter.service.content.mapper.ProjectMapper;
import ru.ibs.socrates.confexporter.service.content.service.ProjectService;


/**
 * Сервис для работы с проектами контента.
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class ProjectServiceImpl implements ProjectService {
  
  private final ProjectMapper projectMapper;
  private final ProjectDaoService projectDaoService;
  private final MessageDaoService messageDaoService;

  @Override
  public ProjectResponse projectFromTimestamp(OffsetDateTime timestamp) {
    return projectMapper.toProjectResponse(
        projectDaoService.getProjectUpdateAfter(timestamp));
  }

  @Override
  public ProjectContentResponse projectContent(String sourceId) {
    UUID sourceIdUuid = UUID.fromString(sourceId);
    return projectMapper.toProjectContentResponse(
        projectDaoService.getBySourceId(sourceIdUuid),
        messageDaoService.getProjectContent(sourceIdUuid, null));
  }
  

  @Override
  public ProjectContentResponse getProjectContentFromDate(
      String sourceId, OffsetDateTime dateFrom) {
    UUID sourceIdUuid = UUID.fromString(sourceId);
    return projectMapper.toProjectContentResponse(
        projectDaoService.getBySourceId(sourceIdUuid),
        messageDaoService.getProjectContent(sourceIdUuid, dateFrom));
  }

}
