syntax = "proto3";
package kratos.api;

import "google/protobuf/duration.proto";

option go_package = "kra/internal/conf;conf";

message Bootstrap {
  Server server = 1;
  Data data = 2;
  AdminBackend admin = 3;
}

message Server {
  message HTTP {
    string network = 1;
    string addr = 2;
    google.protobuf.Duration timeout = 3;
  }
  HTTP http = 1;
}

message Data {
  message Database {
    string driver = 1;
    string source = 2;
    string host = 3;
    string port = 4;
    string user = 5;
    string password = 6;
    string name = 7;
    string config = 8;
    string path = 9;
    string alias_name = 10;
    bool disable = 11;
    string prefix = 12;
    string engine = 13;
    string log_mode = 14;
    int32 max_idle_conns = 15;
    int32 max_open_conns = 16;
    int32 conn_max_lifetime = 17;
    bool singular = 18;
  }
  message Redis {
    string network = 1;
    string addr = 2;
    google.protobuf.Duration read_timeout = 3;
    google.protobuf.Duration write_timeout = 4;
    string name = 5;
    string password = 6;
    int32 db = 7;
    bool use_cluster = 8;
    repeated string cluster_addrs = 9;
  }
  message MongoHost {
    string host = 1;
    string port = 2;
  }
  message Mongo {
    string coll = 1;
    string options = 2;
    string database = 3;
    string username = 4;
    string password = 5;
    string auth_source = 6;
    uint64 min_pool_size = 7;
    uint64 max_pool_size = 8;
    int64 socket_timeout_ms = 9;
    int64 connect_timeout_ms = 10;
    bool is_zap = 11;
    repeated MongoHost hosts = 12;
  }
  Database database = 1;
  Redis redis = 2;
  repeated Database database_list = 3;
  repeated Redis redis_list = 4;
  Mongo mongo = 5;
}

// AdminBackend contains settings for the administration HTTP transport.
message AdminBackend {
  string router_prefix = 1;
  JWT jwt = 2;
  Captcha captcha = 3;
  Local local = 4;
  Email email = 5;
  Storage storage = 6;
  // ConfigPath is populated by the entrypoint and is not required in YAML.
  string config_path = 7;
  Media media = 8;
  repeated Disk disk_list = 9;
  System system = 10;
  Zap zap = 11;
  CORS cors = 12;
  App app = 13;

  message JWT {
    string signing_key = 1;
    google.protobuf.Duration expires_time = 2;
    google.protobuf.Duration buffer_time = 3;
    string issuer = 4;
  }

  message Captcha {
    int32 key_long = 1;
    int32 img_width = 2;
    int32 img_height = 3;
    google.protobuf.Duration store_expiration = 4;
  }

  message Local {
    string store_path = 1;
    string path_prefix = 2;
  }

  message Email {
    string to = 1;
    string from = 2;
    string host = 3;
    string secret = 4;
    string nickname = 5;
    int32 port = 6;
    bool is_ssl = 7;
    bool is_login_auth = 8;
  }

  message Media {
    int32 session_ttl = 1;
    int64 max_file_size = 2;
    string chunk_dir = 3;
  }

  message Disk {
    string mount_point = 1;
  }

  message System {
    bool use_redis = 1;
    bool use_multipoint = 2;
    bool use_strict_auth = 3;
    bool disable_auto_migrate = 4;
    bool use_mongo = 5;
    int32 addr = 6;
    int32 iplimit_count = 7;
    int32 iplimit_time = 8;
  }

  message Zap {
    string level = 1;
    string prefix = 2;
    string format = 3;
    string director = 4;
    string encode_level = 5;
    string stacktrace_key = 6;
    bool show_line = 7;
    bool log_in_console = 8;
    int32 retention_day = 9;
    bool access_req_body = 10;
    bool access_resp_data = 11;
    bool access_req_headers = 12;
    int32 access_log_max_bytes = 13;
    repeated string file_only_modules = 14;
  }

  message CORS {
    string mode = 1;
    repeated CORSRule whitelist = 2;
  }
  message CORSRule {
    string allow_origin = 1;
    string allow_methods = 2;
    string allow_headers = 3;
    string expose_headers = 4;
    bool allow_credentials = 5;
  }
  message App {
    string node = 1;
    string app_id = 2;
    string env = 3;
  }

  message Storage {
    string type = 1;
    Qiniu qiniu = 2;
    ObjectStore aliyun_oss = 3;
    ObjectStore huawei_obs = 4;
    ObjectStore tencent_cos = 5;
    ObjectStore aws_s3 = 6;
    ObjectStore cloudflare_r2 = 7;
    ObjectStore minio = 8;
  }

  message Qiniu {
    string zone = 1;
    string bucket = 2;
    string base_url = 3;
    string access_key = 4;
    string secret_key = 5;
    bool use_https = 6;
    bool use_cdn_domains = 7;
  }

  // ObjectStore covers S3-compatible configuration used by public cloud
  // providers and self-hosted MinIO.
  message ObjectStore {
    string endpoint = 1;
    string region = 2;
    string bucket = 3;
    string access_key = 4;
    string secret_key = 5;
    string base_url = 6;
    string path_prefix = 7;
    bool use_ssl = 8;
    bool force_path_style = 9;
    string account_id = 10;
  }
}

