package com.mzh.library.dao;

import com.mzh.library.entity.Book;
import com.mzh.library.entity.BorrowRecord;
import com.mzh.library.entity.BorrowRecordSearchCriteria;
import com.mzh.library.entity.Reader;

import java.sql.Connection;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

public interface BorrowRecordDao {
    List<BorrowRecord> search(BorrowRecordSearchCriteria criteria);

    List<BorrowRecord> findByReaderId(long readerId);

    Optional<Reader> findReaderByUserId(long userId);

    Optional<Reader> findReaderByIdentifierForUpdate(Connection connection, String identifier);

    Optional<Book> findBookByIdentifierForUpdate(Connection connection, String identifier);

    Optional<BorrowRecord> findByIdForUpdate(Connection connection, long id);

    int countActiveByReaderId(Connection connection, long readerId);

    long create(Connection connection, BorrowRecord record);

    boolean decrementAvailableCopies(Connection connection, long bookId);

    boolean incrementAvailableCopies(Connection connection, long bookId);

    boolean markReturned(Connection connection, long id, LocalDateTime returnedAt);

    boolean renew(Connection connection, long id, LocalDateTime dueAt);
}
