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

import org.springframework.stereotype.Service;

import com.iqser.red.service.persistence.management.v1.processor.entity.configuration.DigitalSignatureTypeEntity;
import com.iqser.red.service.persistence.management.v1.processor.exception.NotFoundException;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.DigitalSignatureTypeRepository;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.configuration.DigitalSignatureType;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
@RequiredArgsConstructor
public class DigitalSignatureTypeService {

    private final DigitalSignatureTypeRepository digitalSignatureTypeRepository;


    public DigitalSignatureType getActiveDigitalSignatureType() {

        return digitalSignatureTypeRepository.findById(DigitalSignatureTypeEntity.ID)
                .map(DigitalSignatureTypeEntity::getDigitalSignatureType)
                .orElseThrow(() -> new NotFoundException("Digital Signature Type is not defined"));
    }


    public void setActiveDigitalSignatureType(DigitalSignatureType digitalSignatureType) {

        digitalSignatureTypeRepository.save(DigitalSignatureTypeEntity.builder().digitalSignatureType(digitalSignatureType).build());
    }


    public void deleteDigitalSignatureType() {

        digitalSignatureTypeRepository.deleteById(DigitalSignatureTypeEntity.ID);
    }

}
