package com.iqser.red.service.persistence.management.v1.processor.service.persistence;

import java.util.Optional;

import org.springframework.stereotype.Service;

import com.iqser.red.service.persistence.management.v1.processor.entity.index.IndexInformationEntity;
import com.iqser.red.service.persistence.management.v1.processor.exception.NotFoundException;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.IndexInformationRepository;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class IndexInformationPersistenceService {

    private final IndexInformationRepository indexInformationRepository;


    public IndexInformationEntity getIndexInformation() {

        Optional<IndexInformationEntity> indexInformation = indexInformationRepository.findById(IndexInformationEntity.ID);
        return indexInformation.orElseThrow(() -> new NotFoundException("Index information does not exist"));
    }


    public void updateIndexInformation(IndexInformationEntity indexInformation) {

        indexInformationRepository.save(indexInformation);
    }

}
