import axios from 'axios'; const api = axios.create({ baseURL: '/api', headers: { 'Content-Type': 'application/json', }, }); export interface SiteConfig { siteTitle: string; subtitle: string; channels: { name: string; url: string }[]; shortText: string; quizParticipationPoints: number; quizCorrectAnswerPoints: number; } export interface RegisterResponse { userId: number; trackingCode: string; } export interface LoginResponse { userId: number; fullName: string; contact: string; isQuizCompleted: boolean; khatmSelections: number[]; } export interface Question { id: number; questionText: string; options: string[]; } export interface QuizSubmitResponse { participationPoints: number; correctCount: number; totalQuizPoints: number; totalScore: number; } export interface UserQuizResponse { questions: UserQuestion[]; participationPoints: number; correctCount: number; totalQuizPoints: number; } export interface UserQuestion { id: number; questionText: string; options: string[]; selectedOption: number; isCorrect: boolean; } export interface KhatmItem { id: number; title: string; url?: string; points: number; } export interface KhatmSaveResponse { success: boolean; totalScore: number; } export interface UserScore { totalScore: number; } export interface AdminReportItem { userId: number; fullName: string; contact: string; trackingCode: string; hasTakenQuiz: boolean; participationPoints: number; correctCount: number; totalQuizPoints: number; khatmTitles: string; totalScore: number; } // Config export const getConfig = () => api.get('/config').then(r => r.data); // User export const registerUser = (fullName: string, contact: string) => api.post('/user/register', { fullName, contact }).then(r => r.data); export const loginUser = (trackingCode: string) => api.post('/user/login', { trackingCode }).then(r => r.data); export const getUserScore = (userId: number) => api.get(`/user/${userId}/score`).then(r => r.data); // Quiz export const getQuestions = () => api.get('/quiz/questions').then(r => r.data); export const submitQuiz = (userId: number, answers: { questionId: number; selectedOption: number }[]) => api.post('/quiz/submit', { userId, answers }).then(r => r.data); export const getUserQuiz = (userId: number) => api.get(`/quiz/user/${userId}`).then(r => r.data); // Khatm export const getKhatmItems = () => api.get('/khatm/items').then(r => r.data); export const saveKhatmSelections = (userId: number, selections: { khatmItemId: number; isSelected: boolean }[]) => api.post('/khatm/save', { userId, selections }).then(r => r.data); // Admin export const getAdminReport = (password: string) => api.get('/admin/report', { params: { password } }).then(r => r.data); export default api;