import {Module} from "@/interfaces";
import {Exam, UserSolution} from "@/interfaces/exam";
import {Assignment} from "@/interfaces/results";
import {create} from "zustand";

export interface ExamState {
	exams: Exam[];
	userSolutions: UserSolution[];
	showSolutions: boolean;
	hasExamEnded: boolean;
	selectedModules: Module[];
	assignment?: Assignment;
	setHasExamEnded: (hasExamEnded: boolean) => void;
	setUserSolutions: (userSolutions: UserSolution[]) => void;
	setExams: (exams: Exam[]) => void;
	setShowSolutions: (showSolutions: boolean) => void;
	setSelectedModules: (modules: Module[]) => void;
	setAssignment: (assignment: Assignment) => void;
	reset: () => void;
}

export const initialState = {
	exams: [],
	userSolutions: [],
	showSolutions: false,
	selectedModules: [],
	hasExamEnded: false,
	assignment: undefined,
};

const useExamStore = create<ExamState>((set) => ({
	...initialState,
	setUserSolutions: (userSolutions: UserSolution[]) => set(() => ({userSolutions})),
	setExams: (exams: Exam[]) => set(() => ({exams})),
	setShowSolutions: (showSolutions: boolean) => set(() => ({showSolutions})),
	setSelectedModules: (modules: Module[]) => set(() => ({selectedModules: modules})),
	setHasExamEnded: (hasExamEnded: boolean) => set(() => ({hasExamEnded})),
	setAssignment: (assignment: Assignment) => set(() => ({assignment})),
	reset: () => set(() => initialState),
}));

export default useExamStore;
