package net.gepafin.tendermanagement.dao; import net.gepafin.tendermanagement.entities.S3ConfigEntity; import net.gepafin.tendermanagement.enums.DocOtherSourceTypeEnum; import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum; import net.gepafin.tendermanagement.repositories.S3ConfigRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component public class S3PathConfig { @Autowired S3ConfigRepository s3ConfigRepository; public String generateDocumentPath(DocumentSourceTypeEnum type, Long callId, Long applicationId) { S3ConfigEntity config = getDocumentPath(type); return config.getParentFolder() + "/" + buildS3Path(config.getPath(), callId, applicationId); } public String generateDocumentPathForOther(DocOtherSourceTypeEnum type, Long callId, Long applicationId) { S3ConfigEntity config = getDocumentPathForOther(type); return config.getParentFolder() + "/" + buildS3Path(config.getPath(), callId, applicationId); } private String buildS3Path(String pathTemplate, Long callId, Long applicationId) { return pathTemplate.replace("{call_id}", callId != null && callId != 0L ? "call_" + callId : "").replace("{application_id}", applicationId != null && applicationId != 0L ? "application_" + applicationId : ""); } public String generateDocumentPathForDelegationAndSignedDocument(DocOtherSourceTypeEnum type) { S3ConfigEntity config = getDocumentPathForOther(type); return config.getParentFolder() + "/" + config.getPath(); } private S3ConfigEntity getDocumentPath(DocumentSourceTypeEnum type) { return s3ConfigRepository.getPathByType(type.name()).orElseThrow(() -> new IllegalArgumentException("No path configuration found for type: " + type)); } private S3ConfigEntity getDocumentPathForOther(DocOtherSourceTypeEnum type) { return s3ConfigRepository.getPathByType(type.name()).orElseThrow(() -> new IllegalArgumentException("No path configuration found for type: " + type)); } public String getBucketNameForOtherType(DocOtherSourceTypeEnum type){ return s3ConfigRepository.getBucketNameByType(type); } public String getBucketNameForCallAppType(DocumentSourceTypeEnum type){ return s3ConfigRepository.getBucketNameByType(type); } }