001/*
002 *  Copyright 2025 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.plugins.repository.trash;
017
018import org.ametys.plugins.repository.AmetysObject;
019import org.ametys.plugins.repository.jcr.JCRAmetysObject;
020
021/**
022 * {@link AmetysObject} which can be moved to trash or restored.
023 */
024public interface TrashableAmetysObject extends JCRAmetysObject
025{
026    /**
027     * Mode of computation for the name if it already exists in JCR.
028     */
029    public enum MergeComputationMode
030    {
031        /** Rename : in case of conflict, the restored object will be renamed */
032        RENAME,
033        /** Update : in case of conflict, the restored object will update the existing one */
034        UPDATE,
035        /** Error : in case of conflict, an error will be thrown */
036        ERROR;
037    }
038    
039    /**
040     * Move this {@link AmetysObject} to the trash.
041     * @return the created trash element that represents the object in the trash
042     */
043    public TrashElement moveToTrash();
044    
045    /**
046     * Restore this {@link AmetysObject} from the trash.
047     * @param mergeComputationMode the merge computation mode, used to know how to behave when restoring an existing element. May be null, as all implementations may not use it.
048     * @implNote when invoked on a object that is not in the trash, this method should have no effect
049     * when invoked on a object in the trash, it should restore the Ametys object in the default workspace and return it.
050     * 
051     * @return the restored ametys object
052     * @throws UnknownParentException if it's not possible to determine a location to restore the object
053     * @throws ConflictingNameException if there is a conflict between restored element or on of child element with existing element
054     */
055    public TrashableAmetysObject restoreFromTrash(MergeComputationMode mergeComputationMode) throws UnknownParentException, ConflictingNameException;
056}