package com.bernard.mcqinator.api.fragenStats;

import android.util.Log;

import com.bernard.mcqinator.api.quiz.Quiz;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.regex.Pattern;

/**
 * @author Mysaa
 * @date on 04/05/17.
 */

public abstract class QuizStat<Q extends Quiz> {

    private static final Pattern QUIZ_FILE_PATTERN = Pattern.compile("^stats_([0-9]+).bernard$");

    public static QuizStat createStat(Class<? extends QuizStat> statClass,Quiz q){
        try {
            QuizStat stat = statClass.newInstance();
            checkedGenDefault(stat,q);
            return stat;
        } catch (InstantiationException e) {
            Log.e("StatCreator","The  class "+statClass.getName()+" is not instatiable ... try to add a 'no arg' constructor",e);
        } catch (IllegalAccessException e) {
            Log.e("StatCreator","The  class "+statClass.getName()+" is not reachable ... try to make it public",e);
        }
        return null;
    }

    @SuppressWarnings("unchecked")
    private static void checkedGenDefault(QuizStat s,Quiz q){
        s.genDefault(q);
    }

    public abstract void genDefault(Q q);


    //////////// Getters / Setters ////////////

    //////////// File Methods ////////////

    public abstract void read(DataInputStream dis) throws IOException;

    public abstract void write(DataOutputStream dos) throws IOException;

}
