package samuelb.capripol.Repositories;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import samuelb.capripol.Sighting;

import java.math.BigDecimal;
import java.util.List;
import java.util.Set;

@Repository
public interface SightingRepository extends JpaRepository<Sighting, Long> {
    @Procedure(name="sightingValue")
    BigDecimal getSightingValue(@Param("baseRating") BigDecimal baseRating, @Param("userID") Long userID, @Param("focusID") Long focusID);

    @Query("SELECT s from Sighting s WHERE s.focus.focusID = ?1 AND s.sightee.userID = ?2")
    public Set<Sighting> findByFocusIDAndUserID(Long focusID, Long userID);

    public List<Sighting> findBySighteeUserID(Long userID);

    @Query("SELECT s from Sighting s WHERE s.sightee.userID =?1 OR s.sighter.userID =?1")
    public List<Sighting> findByUserID(Long userID);

    @Query("SELECT s from Sighting s WHERE s.sighter.userID = ?1 AND s.sightee.userID = ?1")
    public List<Sighting> findSelfClaims(Long userID);

    @Query("SELECT s from Sighting s WHERE s.sighter.userID = ?1 AND s.sightee.userID = ?1 AND s.focus.focusID =?2")
    public List<Sighting> findSelfClaimsForFocus(Long userID, Long focusID);

    @Query("SELECT s from Sighting s WHERE s.sighterSighteeRelationship = ?1 AND s.sightee.userID = ?2")
    public List<Sighting> findByRelationship(String relationship, Long userID);

    @Query("SELECT s from Sighting s WHERE s.sighterSighteeRelationship = ?1 AND s.sighter.userID = ?2")
    public List<Sighting> findByRelationshipGiven(String relationship, Long userID);

    @Query("SELECT s from Sighting s WHERE s.sighterSighteeRelationship = ?1 AND s.sighter.userID = ?2 AND s.focus.focusID =?3")
    public List<Sighting> findClaimsForFocusByRelationShip(String relationship, Long userID, Long focusID);

    @Query("SELECT s from Sighting s WHERE s.sighterSighteeRelationship = ?1 AND s.sightee.userID = ?2 AND s.focus.focusID =?3")
    public List<Sighting> findClaimsForFocusByRelationShipReceived(String relationship, Long userID, Long focusID);
}
