package de.avatic.lcc.service.configuration;

import de.avatic.lcc.repositories.rates.MatrixRateRepository;
import de.avatic.lcc.repositories.rates.ValidityPeriodRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * A service class responsible for approving or verifying rate drafts.
 * Provides functionalities to check for unapproved rate drafts and
 * apply these drafts when necessary.
 */
@Service
public class RateApprovalService {


    private final ValidityPeriodRepository validityPeriodRepository;

    public RateApprovalService(ValidityPeriodRepository validityPeriodRepository) {
        this.validityPeriodRepository = validityPeriodRepository;
    }

    /**
     * Checks if there are any staged (draft) rates that have not yet been approved.
     *
     * @return {@code true} if rate drafts exist, {@code false} otherwise.
     */
    public boolean hasRateDrafts() {
        return validityPeriodRepository.hasRateDrafts();
    }

    /**
     * Approves and applies all staged (draft) rates.
     */
    public void approveRateDrafts() {
        validityPeriodRepository.applyDraft();
    }
}
