/*
 *   Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 *   WSO2 Inc. licenses this file to you 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.
 *
 */
package org.wso2.carbon.device.mgt.core.operation.mgt.dao;

import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;

import java.util.List;
import java.util.Map;

public interface OperationDAO {

    int addOperation(Operation operation) throws OperationManagementDAOException;

    Operation getOperation(int operationId) throws OperationManagementDAOException;

    Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException;

    List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId, Operation.Status status)
            throws OperationManagementDAOException;

    List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId, PaginationRequest request, Operation.Status status)
            throws OperationManagementDAOException;

    List<? extends Operation> getOperationsForDevice(int enrolmentId) throws OperationManagementDAOException;

    int getOperationCountForDevice(int enrolmentId) throws OperationManagementDAOException;

    List<? extends Operation> getOperationsForDevice(int enrolmentId, PaginationRequest request) throws OperationManagementDAOException;

    Operation getNextOperation(int enrolmentId) throws OperationManagementDAOException;

    boolean updateOperationStatus(int enrolmentId, int operationId,Operation.Status status)
            throws OperationManagementDAOException;

    void updateEnrollmentOperationsStatus(int enrolmentId, String operationCode, Operation.Status existingStatus,
                                          Operation.Status newStatus) throws OperationManagementDAOException;

    boolean updateTaskOperation(int enrolmentId, String operationCode) throws OperationManagementDAOException;

    void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
            throws OperationManagementDAOException;

    Activity getActivity(int operationId) throws OperationManagementDAOException;

    List<Activity> getActivityList(List<Integer> operationIds) throws OperationManagementDAOException;

    Activity getActivityByDevice(int operationId, int deviceId) throws OperationManagementDAOException;

    List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementDAOException;

    List<Activity> getFilteredActivities(String operationCode, int limit, int offset) throws OperationManagementDAOException;

    int getTotalCountOfFilteredActivities(String operationCode) throws OperationManagementDAOException;

    List<Activity> getActivitiesUpdatedAfterByUser(long timestamp, String user, int limit, int offset) throws OperationManagementDAOException;

    int getActivityCountUpdatedAfter(long timestamp) throws OperationManagementDAOException;

    int getActivityCountUpdatedAfterByUser(long timestamp, String user) throws OperationManagementDAOException;

    /**
     * This method provides operation mappings for given status
     * @param opStatus Operation status
     * @param pushNotificationStatus Push notification Status
     * @param limit Limit for no devices
     * @return Tenant based operation mappings list
     * @throws OperationManagementDAOException
     */
    Map<Integer, List<OperationMapping>> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushNotificationStatus pushNotificationStatus,
                                                                     int limit) throws OperationManagementDAOException;

}