File size: 6,764 Bytes
65d68f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import { apiGet, apiPost, buildQuery } from "@/lib/api/client";
import { shouldUseDemoData, withDemoFallback } from "@/lib/api/mode";
import { delay } from "@/lib/frontend-demo-data";
import type {
  DiagnosticQuiz,
  DiagnosticResultRequest,
  DiagnosticResultResponse,
  WhatToStudyResponse,
  StudyPathResponse,
  ExamIntelligenceResponse,
  VideoPlanV2Response,
  StudyPathPlanType,
  VideoPlanDurationType,
  VideoPlanStyle,
  StudentLevel,
} from "@/lib/api/types";

export async function getDiagnosticQuiz(documentId: string): Promise<DiagnosticQuiz> {
  if (shouldUseDemoData(documentId)) {
    return delay(mockDiagnosticQuiz(documentId));
  }
  return withDemoFallback(
    () => apiGet<DiagnosticQuiz>(`/intelligence/diagnostic-quiz/${documentId}`),
    () => delay(mockDiagnosticQuiz(documentId)),
  );
}

export async function submitDiagnosticResults(payload: DiagnosticResultRequest): Promise<DiagnosticResultResponse> {
  if (shouldUseDemoData(payload.document_id)) {
    return delay({
      student_level: "intermediate",
      weak_areas: ["diagram", "answer_writing"],
      analysis: "You understand the concepts well but need practice in structuring long answers and drawing neat diagrams.",
    });
  }
  return withDemoFallback(
    () => apiPost<DiagnosticResultResponse, DiagnosticResultRequest>("/intelligence/diagnostic-results", payload),
    () => delay({
      student_level: "intermediate",
      weak_areas: ["diagram", "answer_writing"],
      analysis: "You understand the concepts well but need practice in structuring long answers and drawing neat diagrams.",
    }),
  );
}

export async function getWhatToStudy(
  documentId: string,
  studentLevel: StudentLevel = "intermediate",
  goal: string = "good marks",
): Promise<WhatToStudyResponse> {
  if (shouldUseDemoData(documentId)) {
    return delay(mockWhatToStudy());
  }
  return withDemoFallback(
    () => apiPost<WhatToStudyResponse, Record<string, never>>(
      `/intelligence/what-to-study${buildQuery({
        document_id: documentId,
        student_level: studentLevel,
        goal,
      })}`,
      {},
    ),
    () => delay(mockWhatToStudy()),
  );
}

export async function getStudyPath(
  documentId: string,
  planType: StudyPathPlanType,
  studentLevel: StudentLevel = "intermediate",
  goal: string = "good marks",
): Promise<StudyPathResponse> {
  if (shouldUseDemoData(documentId)) {
    return delay(mockStudyPath(planType));
  }
  return withDemoFallback(
    () => apiPost<StudyPathResponse, Record<string, never>>(
      `/intelligence/study-path${buildQuery({
        document_id: documentId,
        plan_type: planType,
        student_level: studentLevel,
        goal,
      })}`,
      {},
    ),
    () => delay(mockStudyPath(planType)),
  );
}

export async function getExamIntelligence(documentId: string): Promise<ExamIntelligenceResponse> {
  if (shouldUseDemoData(documentId)) {
    return delay(mockExamIntelligence());
  }
  return withDemoFallback(
    () => apiGet<ExamIntelligenceResponse>(`/intelligence/exam-intelligence/${documentId}`),
    () => delay(mockExamIntelligence()),
  );
}

export async function getVideoPlanExtended(
  documentId: string,
  durationType: VideoPlanDurationType,
  style: VideoPlanStyle,
): Promise<VideoPlanV2Response> {
  if (shouldUseDemoData(documentId)) {
    return delay(mockVideoPlan(durationType, style));
  }
  return withDemoFallback(
    () => apiPost<VideoPlanV2Response, Record<string, never>>(
      `/intelligence/video-plan-extended${buildQuery({
        document_id: documentId,
        duration_type: durationType,
        style,
      })}`,
      {},
    ),
    () => delay(mockVideoPlan(durationType, style)),
  );
}

// Mock Helpers for Demo Mode
function mockDiagnosticQuiz(docId: string): DiagnosticQuiz {
  return {
    id: "diag-local",
    document_id: docId,
    questions: [
      {
        id: "q1",
        category: "concept",
        question: "What is the primary principle behind this chapter?",
        options: ["Option A", "Option B", "Option C", "Option D"],
        correct_answer_index: 0,
      },
      {
        id: "q2",
        category: "memory",
        question: "Define the core term used in section 2.",
        options: ["Def A", "Def B", "Def C", "Def D"],
        correct_answer_index: 1,
      },
    ],
  };
}

function mockWhatToStudy(): WhatToStudyResponse {
  return {
    must_study_topics: [{ topic: "Core Concept", reason: "Foundational for 60% of marks" }],
    high_weightage_topics: [{ topic: "Section 3.1", reason: "Strong topic in the selected material" }],
    repeated_pyq_topics: [{ topic: "Definition X", reason: "Use uploaded verified papers before claiming repetition" }],
    low_priority_topics: [{ topic: "Historical Context", reason: "Review after core scoring concepts" }],
    skip_for_now_topics: [{ topic: "Advanced Proofs", reason: "Beyond standard syllabus" }],
    revision_keywords: ["Keyword 1", "Keyword 2"],
    easy_marks: [{ topic: "Diagram Y", reason: "Simple to draw, carries 3 marks" }],
    danger_areas: [{ topic: "Sign Convention", reason: "Students lose marks here frequently" }],
    study_order: ["Core Concept", "Section 3.1", "Definition X"],
  };
}

function mockStudyPath(planType: StudyPathPlanType): StudyPathResponse {
  return {
    plan_type: planType,
    total_estimated_coverage: "85%",
    blocks: [
      {
        time_block: "00:00 - 00:20",
        topic: "Fast Recap",
        reason: "Based on 1h emergency mode",
        task: "Read summary keywords",
        output_expected: "Mental map of chapter",
        revision_checkpoint: "Recall top 3 laws",
      },
    ],
  };
}

function mockExamIntelligence(): ExamIntelligenceResponse {
  return {
    chapter: "Sample Chapter",
    topic_importance: "High",
    pyq_pattern: "Focuses on numericals in part B",
    likely_question_types: ["MCQ", "Long Answer"],
    answers: [
      {
        question: "Explain Z?",
        marks: 4,
        answer_structure: "Intro -> Law -> Diagram -> Conclusion",
        key_points: ["Point 1", "Point 2"],
        diagram_suggested: true,
      },
    ],
    common_mistakes: ["Units error", "Formula mismatch"],
    keywords_to_underline: ["Specific Term 1", "Specific Term 2"],
  };
}

function mockVideoPlan(duration: VideoPlanDurationType, style: VideoPlanStyle): VideoPlanV2Response {
  return {
    title: "Intelligence Masterclass",
    duration_type: duration,
    style: style,
    hook: "Imagine you could control energy...",
    analogy: "Like water flowing through a pipe",
    recap: "We covered X, Y and Z today.",
    sections: [
      { scene_number: 1, label: "Intro", copy: "Hi, I am DocDoe...", visual_suggestion: "Show mascot waving" },
    ],
    mini_quiz: [],
  };
}