syntax = "proto3";

package types;

// 发行信息
message Issuance {
    string   issuanceId                        = 1;  //发行ID,一期发行对应一个ID
    int64    totalBalance                      = 2;  //当期发行的总金额(ccny)
    int64    debtCeiling                       = 3;  //单用户可借出的限额(ccny)
    int64    liquidationRatio                  = 4;  //清算比例
    int64    collateralValue                   = 5;  //抵押物总数量(bty)
    int64    debtValue                         = 6;  //产生的ccny数量
    repeated DebtRecord debtRecords            = 7;  //大户抵押记录
    repeated DebtRecord invalidRecords         = 8;  //大户抵押记录
    int32               status                 = 9;  //当期发行的状态，是否关闭
    int64               latestLiquidationPrice = 10; //最高清算价格
    int64               period                 = 11; //发行最大期限
    int64               latestExpireTime       = 12; //最近超期时间
    int64               createTime             = 13; //创建时间
    int64               balance                = 14; //剩余可发行ccny
    string              issuerAddr             = 15; //发行地址
}

// 抵押记录
message DebtRecord {
    string accountAddr      = 1;  //抵押人地址
    int64  startTime        = 2;  //抵押时间
    int64  collateralValue  = 3;  //抵押物价值(bty)
    int64  collateralPrice  = 4;  //抵押物价格
    int64  debtValue        = 5;  //债务价值(ccny)
    int64  liquidationPrice = 6;  //抵押物清算价格
    int32  status           = 7;  //抵押状态，是否被清算
    int64  liquidateTime    = 8;  //清算时间
    int64  expireTime       = 9;  //超时清算时间
    int32  preStatus        = 10; //上一次抵押状态，用于告警恢复
    string debtId           = 11; //借贷id
    string issuId           = 12; //发行id
}

// 资产价格记录
message IssuanceAssetPriceRecord {
    int64 recordTime = 1; //价格记录时间
    int64 btyPrice   = 2; // bty价格
}

// action
message IssuanceAction {
    oneof value {
        IssuanceCreate create = 1; //创建一期发行
        IssuanceDebt   debt   = 2; //抵押
        IssuanceRepay  repay  = 3; //清算
        IssuanceFeed   feed   = 4; //喂价
        IssuanceClose  close  = 5; //关闭
        IssuanceManage manage = 6; //全局配置
    }
    int32 ty = 10;
}

message IssuanceManage {
    repeated string superAddrs = 1; //大户地址
}

// 创建发行
message IssuanceCreate {
    int64 totalBalance     = 1; //发行总金额
    int64 debtCeiling      = 2; //单用户可借出的限额(ccny)
    int64 liquidationRatio = 3; //清算比例
    int64 period           = 4; //发行最大期限
}

// 抵押
message IssuanceDebt {
    string issuanceId = 1; //发行ID
    int64  value      = 2; //借贷金额(ccny)
}

// 质押清算
message IssuanceRepay {
    string issuanceId = 1; //发行ID
    string debtId     = 2; //抵押ID
}

// 喂价
message IssuanceFeed {
    int32    collType     = 1; //抵押物价格类型(1，bty，2，btc，3，eth...)
    repeated int64 price  = 2; //喂价
    repeated int64 volume = 3; //成交量
}

// 借贷关闭
message IssuanceClose {
    string issuanceId = 1; //发行ID
}

// exec_local 发行信息
message ReceiptIssuance {
    string issuanceId  = 1;
    string accountAddr = 2;
    string debtId      = 3;
    int32  status      = 4;
}

// exec_local issuid记录信息
message ReceiptIssuanceID {
    string issuanceId = 1;
    int32  status     = 2;
}

// exec_local 抵押记录信息列表
message IssuanceRecords {
    repeated ReceiptIssuance records = 1;
}

// 根据ID查询发行信息
message ReqIssuanceInfo {
    string issuanceId = 1;
}

// 返回一期发行信息
message RepIssuanceCurrentInfo {
    int32  status           = 1;  //当期发行的状态，是否关闭
    int64  totalBalance     = 2;  //当期发行总金额(ccny)
    int64  debtCeiling      = 3;  //单用户可借出的限额(ccny)
    int64  liquidationRatio = 4;  //清算比例
    int64  balance          = 5;  //剩余可借贷金额(ccny)
    int64  collateralValue  = 6;  //抵押物总数量(bty)
    int64  debtValue        = 7;  //产生的ccny数量
    int64  period           = 8;  //发行最大期限
    string issuId           = 9;  //发行ID
    int64  createTime       = 10; //创建时间
}

// 根据ID列表查询多期发行信息
message ReqIssuanceInfos {
    repeated string issuanceIds = 1;
}

// 返回多期发行信息
message RepIssuanceCurrentInfos {
    repeated RepIssuanceCurrentInfo infos = 1;
}

// 根据发行状态查询
message ReqIssuanceByStatus {
    int32  status     = 1;
    string issuanceId = 2;
}

// 返回发行ID列表
message RepIssuanceIDs {
    repeated string IDs = 1;
}

// 根据用户地址查询抵押记录
message ReqIssuanceRecords {
    string issuanceId = 1;
    string addr       = 2;
    int32  status     = 3;
    string debtId     = 4;
}

// 返回记录列表
message RepIssuanceRecords {
    repeated DebtRecord records = 1;
}

// 返回记录
message RepIssuanceDebtInfo {
    DebtRecord record = 1;
}

// 返回最新抵押物价格
message RepIssuancePrice {
    int64 price = 1; //当前抵押物最新价格
}

// 返回用户发行总额
message RepIssuanceUserBalance {
    int64 balance = 1; //返回用户发行总额
}