package com.viettel.campaign.repository.ccms_full;

import com.viettel.campaign.model.ccms_full.ScenarioAnswer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author anhvd_itsol
 */


@Repository
public interface ScenarioAnswerRepository extends JpaRepository<ScenarioAnswer, Long> {

    List<ScenarioAnswer> findByScenarioQuestionIdAndCompanySiteIdAndStatusOrderByOrderIndex(Long scenarioQuestionId, Long companySiteId, Short status);

    @Query(value="SELECT MAX(orderIndex) FROM ScenarioAnswer WHERE scenarioQuestionId = :scenarioQuestionId AND companySiteId = :companySiteId AND status = 1")
    Long getMaxAnswerOrderId(@Param("scenarioQuestionId") Long scenarioQuestionId, @Param("companySiteId") Long companySiteId);

    Integer deleteScenarioAnswersByScenarioQuestionId(Long scenarioQuestionId);

    ScenarioAnswer findScenarioAnswerByScenarioAnswerId(Long scenarioAnswerId);
}
