syntax = "proto3";

import "google/protobuf/timestamp.proto";
import "gogoproto/gogo.proto";
// import "validate/validate.proto";
import "google/api/annotations.proto";
import "google/protobuf/empty.proto";

package api.v1;

option go_package = "moredoc/api/v1;v1";
option java_multiple_files = true;
option java_package = "api.v1";

message Config {
  int64 id = 1;
  string label = 2;
  string name = 3;
  string value = 4;
  string placeholder = 5;
  string input_type = 6;
  string category = 7;
  int32 sort = 8;
  string options = 9;
  google.protobuf.Timestamp created_at = 10 [ (gogoproto.stdtime) = true ];
  google.protobuf.Timestamp updated_at = 11 [ (gogoproto.stdtime) = true ];
}

message ListConfigRequest { repeated string category = 1; }

message Configs { repeated Config config = 1; }

// 验证码配置
message ConfigCaptcha {
  int32 length = 1;
  int32 width = 2;
  int32 height = 3;
  string type = 4;
}

// 系统配置项
message ConfigSystem {
  string domain = 1;
  string title = 2;
  string keywords = 3;
  string description = 4;
  string logo = 5;
  string favicon = 6;
  string icp = 7;
  string analytics = 8;
  string sitename = 9;
  string copyright_start_year = 10;
  string register_background = 11;
  string login_background = 12;
  repeated string recommend_words = 13;
  string version = 14; // 程序版本号
}

// 底链配置项
message ConfigFooter {
  string about = 1;
  string contact = 2;
  string agreement = 3;
  string copyright = 4;
  string feedback = 5;
}

// 安全配置
message ConfigSecurity {
  bool is_close = 1;
  string close_statement = 2;
  bool enable_register = 3;
  bool enable_captcha_login = 4;
  bool enable_captcha_register = 5;
  bool enable_captcha_comment = 6;
  bool enable_captcha_find_password = 7;
  bool enable_captcha_upload = 8;
  int32 max_document_size = 9;
  repeated string document_allowed_ext = 10;
}

message Settings {
  ConfigSystem system = 1;
  ConfigFooter footer = 2;
  ConfigSecurity security = 3;
  // ConfigCaptcha captcha = 4;
}

message EnvDependent {
  string name = 1;        // 依赖名称
  string description = 2; // 依赖描述
  bool is_installed = 3;  // 是否已安装
  string error = 4;       // 错误信息
  google.protobuf.Timestamp checked_at = 5
      [ (gogoproto.stdtime) = true ]; // 检测时间
  string cmd = 6;                     // 检测命令
  bool is_required = 7;               // 是否必须
}

message Envs { repeated EnvDependent envs = 1; }

message Stats {
  int64 user_count = 1;
  int64 document_count = 2;
  int64 category_count = 3;
  int64 article_count = 4;
  int64 comment_count = 5;
  int64 banner_count = 6;
  int64 friendlink_count = 7;
  string os = 8;
  string version = 9;
  string hash = 10;
  string build_at = 11;
  int64 report_count = 12;
}

service ConfigAPI {
  // 获取系统配置（针对所有用户，只读）
  rpc GetSettings(google.protobuf.Empty) returns (Settings) {
    option (google.api.http) = {
      get : "/api/v1/settings"
    };
  }

  // UpdateConfig 更新配置
  rpc UpdateConfig(Configs) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      put : '/api/v1/config',
      body : '*',
    };
  }

  // ListConfig 查询配置项
  rpc ListConfig(ListConfigRequest) returns (Configs) {
    option (google.api.http) = {
      get : '/api/v1/config/list',
    };
  }

  // 获取系统配置
  rpc GetStats(google.protobuf.Empty) returns (Stats) {
    option (google.api.http) = {
      get : "/api/v1/stats"
    };
  }

  // 获取系统环境依赖检测
  rpc GetEnvs(google.protobuf.Empty) returns (Envs) {
    option (google.api.http) = {
      get : "/api/v1/envs"
    };
  }

  // 更新站点地图
  rpc UpdateSitemap(google.protobuf.Empty) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      put : "/api/v1/sitemap"
    };
  }
}