java.lang.Object
ai.tutor.cab302exceptionalhandlers.controller.ChatSetupController
ai.tutor.cab302exceptionalhandlers.controller.ChatUpdateController

public class ChatUpdateController extends ChatSetupController
Controller for updating existing chats in the AI tutor application.

Extends ChatSetupController to provide functionality for updating an existing chat’s details (e.g., chat name, response attitude, quiz difficulty) and downloading chat messages as a text file. Implements the abstract method setupConfirmChatButton() to handle chat updates and navigation back to the chat screen. Interacts with the database via ChatDAO and MessageDAO for updating chats and retrieving messages, respectively.

See Also:
  • Constructor Details

    • ChatUpdateController

      public ChatUpdateController(SQLiteConnection db, User currentUser, Chat currentChat) throws IllegalStateException, RuntimeException, SQLException
      Constructs a ChatUpdateController with a database connection, authenticated user, and the chat to update.

      Calls the superclass constructor to initialize the database connection, current user, and DAO instances (UserDAO, ChatDAO, MessageDAO). Sets the currentChat to be updated. Throws an exception if the user is null.

      Parameters:
      db - The SQLite database connection
      currentUser - The currently authenticated user
      currentChat - The chat to be updated
      Throws:
      IllegalStateException - If the user is null
      RuntimeException - If unexpected errors occur during setup
      SQLException - If database initialization fails
  • Method Details

    • initialize

      public void initialize()
      Initializes the chat update screen’s UI components and event handlers.

      Calls the superclass’s ChatSetupController.initialize() to set up shared functionality (e.g., exit button, background exit), then configures the UI with existing chat details using configureChatSettings().

      Overrides:
      initialize in class ChatSetupController
    • getCurrentChat

      protected Chat getCurrentChat()
      Retrieves the current chat being updated.

      Overrides the abstract ChatSetupController.getCurrentChat() method to provide the chat context for the update mode. Returns the currentChat field, which is set by the subclass when initializing the update interface.

      Specified by:
      getCurrentChat in class ChatSetupController
      Returns:
      The current Chat object being updated, or null if not set
      See Also:
    • setupConfirmChatButton

      protected void setupConfirmChatButton()
      Sets up the confirm chat button to update the current chat.

      Configures ChatSetupController.startChatButton to update the chat using updateChatDetails(String, String, String, int, String, String) with user inputs from the UI, then navigates back to the chat screen via ChatSetupController.chatReturn(). Displays an error alert if the update fails.

      Specified by:
      setupConfirmChatButton in class ChatSetupController
    • downloadChat

      protected void downloadChat()
      Initiates the download of chat messages for the current chat as a text file.

      Checks if a chat is selected using getCurrentChat(), retrieves all messages for the chat using MessageDAO, formats them into a text file, and prompts the user to save it using a FileChooser. Displays alerts for no chat selected, no messages, or successful/failed operations. Subclasses are responsible for providing the chat context.

      Overrides:
      downloadChat in class ChatSetupController
    • updateChatDetails

      public void updateChatDetails(String name, String responseAttitude, String quizDifficulty, int quizLength, String educationLevel, String studyArea) throws IllegalArgumentException, NoSuchElementException, SQLException
      Updates the details of the current chat.

      Validates the required inputs (chat name, response attitude, quiz difficulty), updates the currentChat object with new values, and saves the changes to the database using ChatSetupController.chatDAO. Optional fields (education level, study area) are set to null if empty.

      Parameters:
      name - The updated name of the chat
      responseAttitude - The updated AI response attitude (e.g., formal, casual)
      quizDifficulty - The updated quiz difficulty level (e.g., easy, medium, hard)
      quizLength - The updated number of questions in a quiz
      educationLevel - The updated user education level (optional, can be null)
      studyArea - The updated user study area or topic (optional, can be null)
      Throws:
      IllegalArgumentException - If the chat name, response attitude, or quiz difficulty is empty
      NoSuchElementException - If the chat does not exist in the database
      SQLException - If database operations fail