package com.kamco.cd.training.postgres.core;

import com.kamco.cd.training.postgres.repository.upload.UploadSessionRepository;
import com.kamco.cd.training.upload.dto.UploadDto;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class UploadSessionCoreService {

  private final UploadSessionRepository uploadSessionRepository;

  public void createUploadSession(UploadDto.UploadAddReq addReq) {
    /*
    UUID newUuid = UUID.randomUUID();

    UploadSessionEntity entity = new UploadSessionEntity();
    entity.setUploadId(addReq.getUploadId());
    entity.setDatasetId(addReq.getDatasetId());
    entity.setFileName(addReq.getFileName());
    entity.setFileSize(addReq.getFileSize());
    entity.setFinalPath(addReq.getFinalPath());
    entity.setStatus(addReq.getStatus());
    entity.setTempPath(addReq.getTempPath());
    entity.setChunkIndex(addReq.getChunkIndex());
    entity.setChunkTotalIndex(addReq.getChunkTotalIndex());
    entity.setUploadDivi(addReq.getUploadDivi());
    entity.setFileHash(addReq.getFileHash());
    entity.setUuid(newUuid);

    //System.out.println("======================");

    UploadSessionEntity saved = uploadSessionRepository.save(entity);

    return String.valueOf(saved.getUuid());
    */

    uploadSessionRepository.insertUploadSession(addReq);
  }

  public UploadDto.uploadDto findByDatasetUid(String uploadDivi, UUID uuid) {
    return uploadSessionRepository.findByDatasetUid(uploadDivi, uuid);
  }

  public UploadDto.uploadDto findByUuid(String uuid) {
    return uploadSessionRepository.findByUuid(uuid);
  }

  public void updateUploadSessionStatus(UploadDto.UploadAddReq addReq) {
    uploadSessionRepository.updateUploadSessionStatus(addReq);
  }
}
