
package com.abm.mainet.common.workflow.repository;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import com.abm.mainet.common.workflow.domain.WorflowTaskMasterDTLEntity;

/**
 * @author kailash.agarwal
 *
 */
public interface ITaskMasterDetailRepository extends CrudRepository<WorflowTaskMasterDTLEntity, Long> {

    @Query("SELECT wfd FROM WorflowTaskMasterDTLEntity wfd WHERE wfd.applicationId=:applicationId and wfd.taskStatus=:taskStatus")
    public WorflowTaskMasterDTLEntity findApplicationCurrentTask(@Param("applicationId") Long applicationId,
            @Param("taskStatus") String taskStatus);

    @Query("SELECT wfd FROM WorflowTaskMasterDTLEntity wfd WHERE wfd.applicationId=:applicationId and wfd.taskStatus in (:taskStatus)")
    public WorflowTaskMasterDTLEntity findApplicationCurrentTask(@Param("applicationId") Long applicationId,
            @Param("taskStatus") String[] taskStatus);

    @Query("SELECT wfd FROM WorflowTaskMasterDTLEntity wfd WHERE wfd.id = (select max(wfdd.id) FROM WorflowTaskMasterDTLEntity wfdd where wfdd.applicationId=:applicationId  and wfdd.taskStatus=:taskStatus)")
    public WorflowTaskMasterDTLEntity findApplicationLastTask(@Param("applicationId") Long applicationId,
            @Param("taskStatus") String taskStatus);

    @Query("SELECT wfd FROM WorflowTaskMasterDTLEntity wfd where wfd.applicationId=:applicationId  and wfd.stepNo=:stepNo")
    public WorflowTaskMasterDTLEntity findTaskByStepNo(@Param("applicationId") Long applicationId, @Param("stepNo") Long stepNo);

}
