package edu.fiu.repositories;

import edu.fiu.models.Activity;
import org.jdbi.v3.sqlobject.config.RegisterRowMapper;
import org.jdbi.v3.sqlobject.customizer.BindBean;
import org.jdbi.v3.sqlobject.statement.GetGeneratedKeys;
import org.jdbi.v3.sqlobject.statement.SqlQuery;
import org.jdbi.v3.sqlobject.statement.SqlUpdate;

import java.util.List;

/**
 * Provides CRUD operations for {@link Activity} through the JDBI
 */
@RegisterRowMapper(Activity.Mapper.class)
public interface ActivityRepository
{

    /**
     * Lists all activity records
     * @return List of all activities
     */
    @SqlQuery("select * from activities")
    List<Activity> list();

    /**
     * Returns a matching Activity object for a user record matching the given ID
     * @param id ID of user to get
     * @return List of all user records as Activity objects
     */
    @SqlQuery("select * from activities where id = :id")
    Activity get(int id);

    /**
     * Creates a activity record for the given activity object
     * @param activity object to create a record for
     * @return true if successful, false otherwise. 
     */
    @SqlUpdate("insert into activities (id, name, type, dataPath, status) values (:id, :name, :type, :dataPath, :status)")
    @GetGeneratedKeys
    Integer create(@BindBean Activity activity);


        /**
     * Creates a activity record for the given activity object
     * @param activity object to create a record for
     * @return true if successful, false otherwise. 
     */
    @SqlUpdate("insert into activities (id, name, type, dataPath, status) values (:id, :name, :type, :dataPath, :status)")
    void create2(Integer id, String name, String type, String dataPath, String status);


    /**
     * Updates the activity record for the given activity object
     * @param activity activity object to update values for
     * @return true if activity entry was updated, false otherwise
     */
    @SqlUpdate("update activities set name=:activity.name, type=:activity.type where id=:activity.id")
    boolean update(@BindBean Activity activity);

    /**
     * Deletes the activity record for the given activity object
     * @param activity Activity object to remove a record for
     * @return true if activity entry was deleted, false otherwise
     */
    @SqlUpdate("delete from activities where id=:id")
    boolean delete(int id);

    /**
     * Updates the status of an activity
     * @return true if activity entry was updated, false otherwise
     */
    @SqlUpdate("update activities set status=:status where id=:id")
    boolean updateStatus(int id, String status);
}
