package com.devjob.repository;

import com.devjob.domain.Application;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface ApplicationRepository extends JpaRepository<Application, Long> {

    boolean existsByMemberIdAndJobId(Long memberId, Long jobId);

    /**
     * 내 지원 내역 목록 — Job, Company까지 fetch join하여 N+1을 방지한다.
     */
    @Query("""
            SELECT a FROM Application a
            JOIN FETCH a.job j
            JOIN FETCH j.company
            WHERE a.member.id = :memberId
            ORDER BY a.createdAt DESC
            """)
    List<Application> findByMemberIdWithJob(@Param("memberId") Long memberId);
}
