/********************************************************************
 * Copyright (c) 2017 Teodor Vecerdi - All Rights Reserved          *
 *                                                                  *
 * This file, QueryManager.java,                                    *
 * is part of this project, MovieList 2.0,                          *
 * which is released under GNU GPLv3.                               *
 * See file LICENSE.MD for full license details.                    *
 * You may use, distribute and modify this code under the terms of  *
 * the previously said license.                                     *
 * You should have received a copy of the GNU GPLv3 license with    *
 * this project.                                                    *
 ********************************************************************/

package com.teodor.vecerdi.movielist.utils;

/**
 * <h1>QueryManager class</h1>
 * <p>This class stores some of the SQL queries for easier access</p>
 *
 * @author Teodor Vecerdi
 */
public class QueryManager {

    /**
     * <p>This field represents the SELECT statement that retrieves the username, salt and password for a given user</p>
     */
    public static final String LOGIN_VERIFICATION = "SELECT username, salt, password FROM accounts WHERE username = ?";
    /**
     * <p>This field represents the INSERT statement that adds a new user to the table</p>
     */
    public static final String ADD_NEW_ACCOUNT = "INSERT INTO accounts(username, salt, password, firstname, lastname, email) VALUES (?, ?, ?, ?, ?, ?)";
    /**
     * <p>This field represents the SELECT statement that checks if a username exists</p>
     */
    public static final String USERNAME_ALREADY_EXISTS = "SELECT * FROM accounts WHERE username = ?";

    /**
     * <p>This field represents the SELECT statement that gets all the movies from a list</p>
     *
     * @param username The username
     * @param list     The selected list
     * @return a String that represents a SQL statement
     */
    public static String FULL_TABLE_ALL(String username, String list) {
        return "SELECT movielist.title, " + username + "_movielist.Watched, movielist.rating, movielist.genre, movielist.rated, movielist.runtime, UserComment, movielist.plot, movielist.poster, movielist.imdbID FROM movielist, " + username + "_movielist WHERE " + username + "_movielist.ListName = '" + list + "' AND movielist.title = " + username + "_movielist.MovieTitle";
    }

    /**
     * <p>This field represents the SELECT statement that gets all the movies from a list based on a search term</p>
     *
     * @param username The username
     * @param list     The selected list
     * @param title    The search term
     * @return a String that represents a SQL statement
     */
    public static String FULL_TABLE_SEARCH(String username, String list, String title) {
        return "SELECT movielist.title, " + username + "_movielist.Watched, movielist.rating, movielist.genre, movielist.rated, movielist.runtime, UserComment, movielist.plot, movielist.poster, movielist.imdbID FROM movielist, " + username + "_movielist WHERE (movielist.title LIKE '%" + title + "%') AND " + username + "_movielist.ListName = '" + list + "' AND movielist.title = " + username + "_movielist.MovieTitle";
    }

}

