package com.infinite.focus.server.auth;

import java.lang.Iterable;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;

public interface AccessCodeRepository extends PagingAndSortingRepository<AccessCode, Long> {
	
	AccessCode findByAccessCode(String accessCode);
	
	@Query(value = "SELECT * FROM access_code WHERE instructor_id = ?1", nativeQuery = true)
	Iterable<AccessCode> findByInstructorId(Long instructor_id);

	@Query(value = "SELECT * FROM access_code WHERE instructor_id = ?1 and status = ?2", nativeQuery = true)
	Page<AccessCode> findByInstructorIdAndStatus(Long instructor_id, String status, Pageable pageable);
	
	@Query(value = "SELECT * FROM access_code WHERE student_id = ?1", nativeQuery = true)
	AccessCode findByStudentId(Long student_id);
	
	@Query(value = "SELECT * FROM access_code WHERE student_id = ?1 and instructor_id = ?2", nativeQuery = true)
	AccessCode findByStudentIdAndInstructorId(Long student_id, Long instructor_id);
}