import { Module } from "@/interfaces";
import { Exam, Shuffles, UserSolution } from "@/interfaces/exam";
import { Assignment } from "@/interfaces/results";
import { Action } from "./reducers";


export interface Navigation {
	previousDisabled: boolean;
	nextDisabled: boolean;
	previousLoading: boolean;
	nextLoading: boolean;
}

export interface StateFlags {
	timeIsUp: boolean;
	reviewAll: boolean;
	finalizeModule: boolean;
	finalizeExam: boolean;
	pendingEvaluation: boolean;
}

export interface ExamState {
	exams: Exam[];
	userSolutions: UserSolution[];
	showSolutions: boolean;
	selectedModules: Module[];
	assignment?: Assignment;
	timeSpent: number;
	timeSpentCurrentModule: number;
	sessionId: string;
	moduleIndex: number;
	exam?: Exam;
	partIndex: number;
	exerciseIndex: number;
	questionIndex: number;
	inactivity: number;
	shuffles: Shuffles[];
	bgColor: string;
	user: undefined | string;
	currentSolution?: UserSolution | undefined;
	navigation: Navigation;
	flags: StateFlags,
	evaluated: UserSolution[];
}


export interface ExamFunctions {
	setUser: (user: string) => void;

	setShowSolutions: (showSolutions: boolean) => void;
	setExams: (exams: Exam[]) => void;
	setSelectedModules: (modules: Module[]) => void;
	setModuleIndex: (moduleIndex: number) => void;
	setExam: (exam?: Exam) => void;

	setPartIndex: (partIndex: number) => void;
	setExerciseIndex: (exerciseIndex: number) => void;
	setQuestionIndex: (questionIndex: number) => void;
	setBgColor: (bgColor: string) => void;

	setShuffles: (shuffles: Shuffles[]) => void;

	setSessionId: (sessionId: string) => void;
	setUserSolutions: (userSolutions: UserSolution[]) => void;

	setTimeIsUp: (timeIsUp: boolean) => void;

	setEvaluated: (evaluated: UserSolution[]) => void,

	saveSession: () => Promise<void>;

	saveStats: () => Promise<void>;

	setNavigation: (updates: Partial<Navigation>) => void;
	setFlags: (updates: Partial<StateFlags>) => void;

	reset: () => void;

	dispatch: (action: Action) => void;
}
