<commit_before>package com.csci4448.MediaManagementSystem.controller;

import com.csci4448.MediaManagementSystem.model.review.ReviewDAO;
import com.csci4448.MediaManagementSystem.model.user.UserDAO;
import com.csci4448.MediaManagementSystem.model.media.MediaDAO;
import com.csci4448.MediaManagementSystem.model.media.Media;
import com.csci4448.MediaManagementSystem.ui.*;
import com.csci4448.MediaManagementSystem.ui.components.*;

public class MainController {

    private Display display;
    private UserDAO userDAO;
    private MediaDAO mediaDAO;
    private ReviewDAO reviewDAO;

    public MainController() {
        userDAO = new UserDAO();
        mediaDAO = new MediaDAO();
        reviewDAO = new ReviewDAO();
        display = new Display(this);
        loginRequest();
    }


    public void loginRequest() {
        display.setState(new LoginPanel(this));
    }

    public void loginSubmitRequest(String username, String password) {

        if (userDAO.userExists(username, password)) {
            userDAO.setActiveUser(username, password);
            storeRequest();
        }
        else {
            //Todo: Pass error message to UI saying that either username or password was incorrect

        }

    }

    public void createAccountRequest() {
        display.setState(new CreateAccountPanel(this));
    }

    public void createAccountSubmitRequest(String firstName, String lastName, String username, String email, String password) {

        if (userDAO.userExists(username, password)) {
            //ToDo: Send error message in UI that user already exists with that username
        }
        else {
            int res = userDAO.addUser(username, password, email, firstName, lastName);
            if (res == -1) {
                //ToDo: Error creating user, send error message to UI
            }
            else {
                userDAO.setActiveUser(username, password);
                storeRequest();
            }
        }

    }

    public void storeRequest() {
        GridMediaPanel store = new GridMediaPanel(this, 215, 327, 15, 35);
        store.getMenuPanel().getStoreButton().setIsSelected(true);
        //ToDo: populate store with media in db
        for (int i = 0; i < 20; i++) {
            MediaListing listing = new MediaListing(this, 1234, "src/main/resources/test.png", "Title", 3.99);
            store.add(listing);
        }
        display.setState(store);
    }

    public void libraryRequest() {
        GridMediaPanel library = new GridMediaPanel(this, 215, 327, 15, 35);
        library.getMenuPanel().getLibraryButton().setIsSelected(true);
        //ToDo: populate library with media in users inventory
        for (int i = 0; i < 3; i++) {
            //ToDo: modify MediaListing so it displays owned/rented instead of price
            MediaListing listing = new MediaListing(this, 1234, "src/main/resources/test.png", "Title", 4);
            library.add(listing);
        }
        display.setState(library);
    }

    public void adminRequest() {
        /* display.setState(new IndividualMediaPanel(this, null)); */
    }

    public void addFundsRequest() {

    }

    public void individualMediaRequest(int mediaId) {
        //ToDo: get info for particular media, mediaId, and add info to panel
        mediaDAO.setActiveMedia(mediaId);

        if (!mediaDAO.activeMediaSet()) {<commit_msg>Fix error with parameter using a double when it should use an integer<commit_after>package com.csci4448.MediaManagementSystem.controller;

import com.csci4448.MediaManagementSystem.model.review.ReviewDAO;
import com.csci4448.MediaManagementSystem.model.user.UserDAO;
import com.csci4448.MediaManagementSystem.model.media.MediaDAO;
import com.csci4448.MediaManagementSystem.model.media.Media;
import com.csci4448.MediaManagementSystem.ui.*;
import com.csci4448.MediaManagementSystem.ui.components.*;

public class MainController {

    private Display display;
    private UserDAO userDAO;
    private MediaDAO mediaDAO;
    private ReviewDAO reviewDAO;

    public MainController() {
        userDAO = new UserDAO();
        mediaDAO = new MediaDAO();
        reviewDAO = new ReviewDAO();
        display = new Display(this);
        loginRequest();
    }


    public void loginRequest() {
        display.setState(new LoginPanel(this));
    }

    public void loginSubmitRequest(String username, String password) {

        if (userDAO.userExists(username, password)) {
            userDAO.setActiveUser(username, password);
            storeRequest();
        }
        else {
            //Todo: Pass error message to UI saying that either username or password was incorrect

        }

    }

    public void createAccountRequest() {
        display.setState(new CreateAccountPanel(this));
    }

    public void createAccountSubmitRequest(String firstName, String lastName, String username, String email, String password) {

        if (userDAO.userExists(username, password)) {
            //ToDo: Send error message in UI that user already exists with that username
        }
        else {
            int res = userDAO.addUser(username, password, email, firstName, lastName);
            if (res == -1) {
                //ToDo: Error creating user, send error message to UI
            }
            else {
                userDAO.setActiveUser(username, password);
                storeRequest();
            }
        }

    }

    public void storeRequest() {
        GridMediaPanel store = new GridMediaPanel(this, 215, 327, 15, 35);
        store.getMenuPanel().getStoreButton().setIsSelected(true);
        //ToDo: populate store with media in db
        for (int i = 0; i < 20; i++) {
            MediaListing listing = new MediaListing(this, 1234, "src/main/resources/test.png", "Title", 4);
            store.add(listing);
        }
        display.setState(store);
    }

    public void libraryRequest() {
        GridMediaPanel library = new GridMediaPanel(this, 215, 327, 15, 35);
        library.getMenuPanel().getLibraryButton().setIsSelected(true);
        //ToDo: populate library with media in users inventory
        for (int i = 0; i < 3; i++) {
            //ToDo: modify MediaListing so it displays owned/rented instead of price
            MediaListing listing = new MediaListing(this, 1234, "src/main/resources/test.png", "Title", 4);
            library.add(listing);
        }
        display.setState(library);
    }

    public void adminRequest() {
        /* display.setState(new IndividualMediaPanel(this, null)); */
    }

    public void addFundsRequest() {

    }

    public void individualMediaRequest(int mediaId) {
        //ToDo: get info for particular media, mediaId, and add info to panel
        mediaDAO.setActiveMedia(mediaId);

        if (!mediaDAO.activeMediaSet()) {
{'fraction_non_alphanumeric': 0.09692601853213707, 'fraction_numerical': 0.019120458891013385, 'mean_word_length': 2.549060542797495, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3528947', 'n_tokens_mistral': 1982, 'n_tokens_neox': 1828, 'n_words': 500}