// Path: Frontend/src/lib/api-types.ts

export type ApiListResponse<T> = {
	data: T[];
};

export type ApiAssignment = {
	id: number;
	classroom_id: number;
	teacher_id: number;
	title: string;
	instructions: string | null;
	pass_threshold?: number;
	status: "draft" | "assigned" | "closed";
	due_at: string | null;
	published_at: string | null;
	created_at: string;
	updated_at: string;
};

export type ApiQuestion = {
	id: number;
	author_teacher_id: number;
	title: string;
	prompt: string;
	topic?: string | null;
	subject: string | null;
	difficulty?: string | null;
	source: string | null;
	correct_answer?: string | null;
	status: string;
	created_at?: string;
	updated_at?: string;
};

export type ApiGeneratedQuestion = {
	question: ApiQuestion;
	tags: string[];
	worked_solution: string[];
};

export type ApiGenerateQuestionsResponse = {
	seed: number;
	data: ApiGeneratedQuestion[];
	count: number;
};

export type ApiAssignmentQuestion = {
	assignment_id: number;
	question_id: number;
	position: number;
	author_teacher_id: number;
	title: string;
	prompt: string;
	subject: string | null;
	source: string | null;
	question_status: string;
	question_created_at?: string | null;
	question_updated_at?: string | null;
};

export type ApiAssignmentStudentQuestionDetail = {
	assignment_id: number;
	student_id: number;
	question_id: number;
	position: number;
	title: string;
	prompt: string;
	subject: string;
	source: string | null;
	question_tags?: string[];
	question_status: string;
	correct_answer?: string;
	answer_id?: number;
	answer_text?: string;
	solve_mode?: "just_answer" | "step_by_step" | "solve_together" | "handwritten";
	working_steps?: string;
	is_correct?: boolean;
	assignment_ai_feedback?: string;
	assignment_teacher_feedback?: string;
	overall_score?: number;
	pass_threshold?: number;
	next_step_outcome?: "redo" | "accept" | "support";
	pass_status_override?: "pending" | "pass" | "no_pass";
	pass_status?: "pending" | "pass" | "no_pass";
	ai_feedback?: string;
	teacher_feedback?: string;
	answer_status?: string;
	review_needs_attention?: boolean;
	review_issue_reason?: string;
	review_correctness_score?: number;
	review_understanding_score?: number;
	review_question_score?: number;
	review_confidence?: number;
	review_tags?: string[];
	submitted_at?: string;
	reviewed_at?: string;
	answer_created_at?: string;
	answer_updated_at?: string;
};

export type ApiUser = {
	id: number;
	email: string;
	role: "student" | "teacher";
	full_name: string;
	is_active: boolean;
	created_at?: string;
	updated_at?: string;
};

export type ApiClassroom = {
	id: number;
	teacher_id: number;
	name: string;
	code?: string | null;
	description?: string | null;
	created_at: string;
	updated_at: string;
};

export type ApiStudent = {
	id: number;
	full_name: string;
	email: string;
	role: string;
	is_active: boolean;
	created_at?: string;
	updated_at?: string;
};

export type ApiReviewSummary = {
	assignment_id: number;
	total_questions: number;
	total_assigned: number;
	not_started: number;
	in_progress: number;
	submitted: number;
	reviewed: number;
};

export type ApiReviewQueueItem = {
	assignment_id: number;
	student_id: number;
	student_name: string;
	student_email: string;
	next_step_outcome?: "redo" | "accept" | "support";
	total_questions: number;
	answered_questions: number;
	reviewed_questions: number;
	submitted_questions: number;
	in_progress_questions: number;
	review_status: string;
	latest_submitted_at?: string;
	latest_reviewed_at?: string;
};

export type ApiStudentWeaknessSummary = {
	student_id: number;
	topic_scores: Record<string, number>;
	weak_tags: string[];
	recent_issues: string[];
};

export type ApiRedoPlanQuestion = {
	topic: string;
	difficulty: string;
	tags: string[];
	reason: string;
};

export type ApiRedoPlan = {
	rationale: string;
	questionSet: ApiRedoPlanQuestion[];
};

export type ApiAssignmentRedoPlanResponse = {
	assignment_id: number;
	student_id: number;
	redo_plan_generated_at?: string | null;
	teacher_feedback?: string | null;
	weakness_summary: ApiStudentWeaknessSummary;
	plan?: ApiRedoPlan | null;
	error?: string | null;
};
