package edu.fiu.models;

import org.jdbi.v3.core.mapper.RowMapper;
import org.jdbi.v3.core.statement.StatementContext;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Stores current progress for an activity as made by a user.
 * State for an activity can be one of:
 * - DONE
 * - IN_PROGRESS
 * - BLANK
 *
 * Uniqueness for instances of this class is ensured by unique pairs of user
 * ID's and activity types.
 *
 * @author Daniel Herrera
 */
public class ActivityProgress {

    public enum ActivityProgressState {
        DONE,
        IN_PROGRESS,
        BLANK
    }

    public ActivityProgressState state; // one of above enums
    public Integer userId; // see edu.fiu.models.User
    public String content; // string representing the frontend's record of progress
    public Integer activityId; // see edu.fiu.models.ActivityType
    public long date; // Unix timestamp

    public ActivityProgress(String state, Integer userId, String content, Integer activityId, long date)
    {
        this.state = ActivityProgressState.valueOf(state);
        this.userId = userId;
        this.content = content;
        this.activityId = activityId;
        this.date = date;
    }

    public static class Mapper implements RowMapper<ActivityProgress> {
        @Override
        public ActivityProgress map(final ResultSet rs, final StatementContext ctx) throws SQLException {

            return new ActivityProgress(
                    rs.getString("state"), rs.getInt("userId"), rs.getString("content"), rs.getInt("activityId"), rs.getLong("date"));
        }
    }

    public String toString() {
        return String.format("Progress(%s, %d, %s, %d, %d)",
                state, userId, content, activityId, date);
    }

    public String getState() {
        return state.toString();
    }

    public Integer getUserId() {
        return userId;
    }

    public String getContent() {
        return content;
    }

    public Integer getActivityId() {
        return activityId;
    }

    public long getDate() {
        return date;
    }
}
