syntax = "proto3";

package next_edu_cloud.content.v1;

import "google/protobuf/struct.proto";

service TextbookService {
  rpc CreateTextbook(CreateTextbookRequest) returns (Textbook);
  rpc GetTextbook(GetTextbookRequest) returns (Textbook);
  rpc ListTextbooks(ListTextbooksRequest) returns (ListTextbooksResponse);
  rpc UpdateTextbook(UpdateTextbookRequest) returns (Textbook);
  rpc DeleteTextbook(DeleteTextbookRequest) returns (Empty);
}

service ChapterService {
  rpc CreateChapter(CreateChapterRequest) returns (Chapter);
  rpc GetChapter(GetChapterRequest) returns (Chapter);
  rpc ListChapters(ListChaptersRequest) returns (ListChaptersResponse);
  rpc UpdateChapter(UpdateChapterRequest) returns (Chapter);
  rpc DeleteChapter(DeleteChapterRequest) returns (Empty);
}

service KnowledgeGraphService {
  rpc GetPrerequisites(GetPrerequisitesRequest) returns (KnowledgePointsResponse);
  rpc GetLearningPath(GetLearningPathRequest) returns (LearningPath);
  rpc AddPrerequisite(AddPrerequisiteRequest) returns (Empty);
  rpc RemovePrerequisite(RemovePrerequisiteRequest) returns (Empty);
}

service QuestionService {
  rpc CreateQuestion(CreateQuestionRequest) returns (Question);
  rpc BatchCreateQuestions(BatchCreateQuestionsRequest) returns (BatchCreateQuestionsResponse);
  rpc GetQuestion(GetQuestionRequest) returns (Question);
  rpc ListQuestions(ListQuestionsRequest) returns (ListQuestionsResponse);
  rpc UpdateQuestion(UpdateQuestionRequest) returns (Question);
  rpc DeleteQuestion(DeleteQuestionRequest) returns (Empty);
  rpc PublishQuestion(PublishQuestionRequest) returns (Empty);
  rpc SearchQuestions(SearchQuestionsRequest) returns (SearchQuestionsResponse);
}

message Empty {}

message Textbook {
  string id = 1;
  string title = 2;
  string subject_id = 3;
  string grade_id = 4;
  string version = 5;
  string status = 6;
  string tenant_id = 7;
  google.protobuf.Struct metadata = 8;
  int64 created_at = 9;
  int64 updated_at = 10;
}

message Chapter {
  string id = 1;
  string textbook_id = 2;
  string title = 3;
  int32 order = 4;
  string parent_id = 5;
  string status = 6;
  int64 created_at = 7;
  int64 updated_at = 8;
}

message KnowledgePoint {
  string id = 1;
  string chapter_id = 2;
  string title = 3;
  string description = 4;
  int32 difficulty = 5;
  google.protobuf.Struct metadata = 6;
  int64 created_at = 7;
  int64 updated_at = 8;
}

message Question {
  string id = 1;
  string knowledge_point_id = 2;
  string type = 3;
  string content = 4;
  google.protobuf.Struct options = 5;
  string answer = 6;
  string explanation = 7;
  int32 difficulty = 8;
  string status = 9;
  string source = 10;
  string created_by = 11;
  google.protobuf.Struct metadata = 12;
  int64 created_at = 13;
  int64 updated_at = 14;
}

// TextbookService request/response messages

message CreateTextbookRequest {
  string title = 1;
  string subject_id = 2;
  string grade_id = 3;
  string version = 4;
  google.protobuf.Struct metadata = 5;
}

message GetTextbookRequest {
  string id = 1;
}

message ListTextbooksRequest {
  string subject_id = 1;
  string grade_id = 2;
  string page_token = 3;
  int32 page_size = 4;
}

message ListTextbooksResponse {
  repeated Textbook textbooks = 1;
  string next_page_token = 2;
}

message UpdateTextbookRequest {
  string id = 1;
  optional string title = 2;
  optional string status = 3;
  google.protobuf.Struct metadata = 4;
}

message DeleteTextbookRequest {
  string id = 1;
}

// ChapterService request/response messages

message CreateChapterRequest {
  string textbook_id = 1;
  string title = 2;
  int32 order = 3;
  string parent_id = 4;
}

message GetChapterRequest {
  string id = 1;
}

message ListChaptersRequest {
  string textbook_id = 1;
  string parent_id = 2;
}

message ListChaptersResponse {
  repeated Chapter chapters = 1;
}

message UpdateChapterRequest {
  string id = 1;
  optional string title = 2;
  optional int32 order = 3;
  optional string status = 4;
}

message DeleteChapterRequest {
  string id = 1;
}

// KnowledgeGraphService request/response messages

message GetPrerequisitesRequest {
  string knowledge_point_id = 1;
  int32 depth = 2;
}

message KnowledgePointsResponse {
  repeated KnowledgePoint points = 1;
}

message GetLearningPathRequest {
  string student_id = 1;
  string subject_id = 2;
}

message LearningPath {
  repeated KnowledgePoint points = 1;
  repeated string recommended_order = 2;
}

message AddPrerequisiteRequest {
  string kp_id = 1;
  string prerequisite_id = 2;
}

message RemovePrerequisiteRequest {
  string kp_id = 1;
  string prerequisite_id = 2;
}

// QuestionService request/response messages

message CreateQuestionRequest {
  string knowledge_point_id = 1;
  string type = 2;
  string content = 3;
  google.protobuf.Struct options = 4;
  string answer = 5;
  string explanation = 6;
  int32 difficulty = 7;
  string source = 8;
  string created_by = 9;
  google.protobuf.Struct metadata = 10;
}

message BatchCreateQuestionsRequest {
  repeated CreateQuestionRequest questions = 1;
}

message BatchCreateQuestionsResponse {
  repeated string ids = 1;
  repeated BatchCreateFailure failed = 2;
}

message BatchCreateFailure {
  int32 index = 1;
  string error = 2;
}

message GetQuestionRequest {
  string id = 1;
}

message ListQuestionsRequest {
  string knowledge_point_id = 1;
  string type = 2;
  int32 difficulty = 3;
  string status = 4;
  string page_token = 5;
  int32 page_size = 6;
}

message ListQuestionsResponse {
  repeated Question questions = 1;
  string next_page_token = 2;
}

message UpdateQuestionRequest {
  string id = 1;
  optional string content = 2;
  optional string answer = 3;
  optional string status = 4;
  google.protobuf.Struct options = 5;
  optional string explanation = 6;
  optional int32 difficulty = 7;
}

message DeleteQuestionRequest {
  string id = 1;
}

message PublishQuestionRequest {
  string id = 1;
}

message SearchQuestionsRequest {
  string q = 1;
  string type = 2;
  int32 difficulty = 3;
  string knowledge_point_id = 4;
  string page_token = 5;
  int32 page_size = 6;
}

message SearchQuestionsResponse {
  repeated Question questions = 1;
  int32 total = 2;
  string next_page_token = 3;
}
