/*-
 * ~~~~~~licensing~~~~~~
 * permission-api
 * ==========
 * Copyright (C) 2020 - 2021 EmDev LLC
 * ==========
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ~~~~~~/licensing~~~~~~
 */
package ru.entaxy.esb.system.core.permission.jpa;

import org.hibernate.Session;
import ru.entaxy.esb.system.core.permission.jpa.entity.Permission;

import java.util.List;
import java.util.Optional;

public interface PermissionService {

    List<Permission> list();

    Permission get(long id);

    List<Permission> getAllById(long id, String type);

    List<Permission> getAllById(Session s, long id, String type);

    Optional<Permission> fetch(long id);

    List<Permission> get(long objectId, String objectType, String action);

    List<Permission> get(Session session, long objectId, String objectType, String action);

    Permission getByAllParameters(long objectId, String objectType, String subjectId, String subjectType, String action);

    Permission getByAllParameters(Session session, long objectId, String objectType, String subjectId, String subjectType, String action);

    Optional<Permission> fetchByAllParameters(long objectId, String objectType, String subjectId, String subjectType, String action);

    boolean existByAllParameters(long objectId, String objectType, String subjectId, String subjectType, String action);

    Permission add(Permission permission);

    Permission addIfNotExist(long objectId, String objectType, String subjectId, String subjectType, String action);

    Permission add(long objectId, String objectType, String subjectId, String subjectType, String action);

    /**
     * Bulk addition of permission
     *
     * @param objectId
     * @param objectType
     * @param subject    - list of list with parameters siquence 1. subjectId 2.subjectType 3.action
     * @return list of permission
     */
    List<Permission> addAll(long objectId, String objectType, List<List<String>> subjects);

    List<Permission> addAll(List<Permission> permissions);

    Permission update(Permission permission);

    Permission update(long permissionId, long objectId, String objectType, String subjectId, String subjectType, String action);

    void remove(long id);

    void remove(long objectId, String objectType, String subjectId, String subjectType, String action);

    void remove(long objectId, String objectType);

    void remove(long objectId, String objectType, String action);

    void remove(String subjectId, String subjectType);

    void remove(String subjectId, String subjectType, String action);

    void removeAll(long objectId, String objectType);

    void removeAll(Session s, long objectId, String objectType);
}
