/**
 * Copyright 2021 Huawei Technologies Co., Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

include "cipher.fbs";
namespace mindspore.schema;

file_identifier "FLJ0";
file_extension "fl";

enum ResponseCode: int {
  SUCCEED=200,  
  SucNotReady=201,  
  RepeatRequest=202,
  SucNotMatch=204,
  OutOfTime=300,
  NotSelected=301,
  RequestError=400, 
  SystemError=500
}

enum AggregationType:byte {FedAvg=0, FedAdam = 1, FedAdagrag=2, FedMeta=3, qffl=4}
enum Metrics:byte {accuracy = 0, precision = 1, recall = 2, AUC = 3,f1=4, fbeta=5}
enum EarlyStopType:byte {loss_diff = 0, loss_abs = 1, weight_diff = 2}

table Aggregation {
  type:AggregationType;
  weights:[float];
}

table EarlyStop {
  early_stop_type:EarlyStopType;
  weight:float;
  rounds:int;    
 }

table FeatureMap{
  weight_fullname:string;
  data:[float];
}
table RequestFLJob{
  fl_name:string;
  fl_id:string;
  iteration:int;
  data_size:int;
  timestamp:string;
}
table ResponseFLJob {
  retcode:int;
  reason:string;
  iteration:int;
  is_selected:bool = false;
  next_req_time:string;
  fl_plan_config:FLPlan;
  feature_map:[FeatureMap];
  timestamp:string;
}

table FLPlan {
  server_mode:string;
  fl_name:string;
  iterations:int;
  epochs:int;
  early_stop:EarlyStop;
  mini_batch:int;
  shuffle:bool = false;
  lr:float;
  aggregation:Aggregation;
  metrics:[Metrics];
  cipher:CipherPublicParams;
}

table RequestUpdateModel{
  fl_name:string;
  fl_id:string;
  iteration:int;
  feature_map:[FeatureMap];
  timestamp:string;
}
table ResponseUpdateModel{
  retcode:int;
  reason:string;
  feature_map:[FeatureMap];
  next_req_time:string;
  timestamp:string;
}

table RequestAsyncUpdateModel{
  fl_name:string;
  fl_id:string;
  iteration:int;
  data_size:int;
  feature_map:[FeatureMap];
}
table ResponseAsyncUpdateModel{
  retcode:int;
  reason:string;
  iteration:int;
}

table RequestPushWeight{
  iteration:int;
  feature_map:[FeatureMap];
}

table ResponsePushWeight{
  retcode:int;
  reason:string;
  iteration:int;
}

table RequestGetModel{
  fl_name:string;
  iteration:int;
  timestamp:string;
}
table ResponseGetModel{
  retcode:int;
  reason:string;
  iteration:int;
  feature_map:[FeatureMap];
  timestamp:string;
}

table RequestAsyncGetModel{
  fl_name:string;
  iteration:int;
}
table ResponseAsyncGetModel{
  retcode:int;
  reason:string;
  iteration:int;
  feature_map:[FeatureMap];
}

table RequestPullWeight{
  iteration:int;
  weight_names:[string];
}
table ResponsePullWeight{
  retcode:int;
  reason:string;
  iteration:int;
  feature_map:[FeatureMap];
}

// FeatureMapList refers to the whole trained model.
table FeatureMapList {
  feature_map:[FeatureMap];
}

table RequestPushMetrics{
  loss:float;
  accuracy:float;
}

table ResponsePushMetrics{
  retcode:int;
}