package com.twu.biblioteca.userOperation;

import com.twu.biblioteca.Inputer;
import com.twu.biblioteca.LibraryElement.Book;
import com.twu.biblioteca.LibraryElement.BookList;
import com.twu.biblioteca.Printer;

import java.util.Optional;

public class Return implements Operation {
    public static final String SUCCESSFUL_RETURN_MESSAGE = "Thank you for returning the book.";
    public static final String UNSUCCESSFUL_RETURN_MESSAGE = "Thank you for returning the book.";
    private Printer printer;
    private Inputer inputer;
    private BookList bookList;

    public Return(Printer printer, Inputer inputer, BookList bookList) {
        this.printer = printer;
        this.inputer = inputer;
        this.bookList = bookList;
    }

    @Override
    public void operate() {
        printer.print("Please Input Book's Name:");
        Optional<Book> returnBook = bookList.getReturnableBook(inputer.input());
        if (returnBook.isPresent()) {
            bookList.returnBook(returnBook.get());
            printer.print(SUCCESSFUL_RETURN_MESSAGE);
        }
    }

    @Override
    public String toString() {
        return "Return Book";
    }
}

@@ -441,38 +441,41 @@
 %22Tha
-nk you for returning the book.
+t is not a valid book to return.3
 %22;%0A 
@@ -1059,16 +1059,87 @@
 SSAGE);%0A
+        %7Delse%7B%0A            printer.print(UNSUCCESSFUL_RETURN_MESSAGE);%0A
         

add unsuccessful return message