/*
 * Copyright (C) 2025  Tim Zimmermann <tim@aglais.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.aglais.zms.db.core.model;

/**
 * A utility class designed to manage and track changes to a data object of type {@code T}.
 * The class provides methods to check if the data has been modified, reset the data to its
 * original state, and update the original state to reflect the current state.
 *
 * @param <T> The type of the data object being managed.
 */
public interface IModifiedStateTracker<T> {

    /**
     * Retrieves the current data being managed by the model.
     *
     * @return The current data of type {@code T} managed by this modifiable model.
     */
    T getData();

    /**
     * Checks if the current state of the data object has been modified compared to its original state.
     * The method compares all declared fields of the data object with those of the original data.
     *
     * @return true if at least one field in the data object differs from the corresponding field in the original data, false otherwise
     */
    boolean isModified();

    /**
     * Updates the original values to match the current state of the data object managed by this model.
     * This method copies all declared field values from the current data object to the original data object,
     * ensuring the original data reflects the most recent state of modifications.
     * <p>
     * It is typically invoked when changes to the current data should be accepted
     * as the new baseline or original state.
     */
    void applyChanges();

    /**
     * Resets the current data object managed by the model to its original state.
     * This method copies all field values from the original data object into the current data object,
     * effectively reverting any modifications that may have been made.
     */
    void discardChanges();
}
