syntax = "proto3";

package types;

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

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

// 资产价格记录
message IssuanceAssetPriceRecord {
    int64      recordTime      = 1; //价格记录时间
    float      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)
    float   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 float price  = 2; //喂价
    repeated int64 volume = 3; //成交量
}

// 借贷关闭
message IssuanceClose {
    string issuanceId = 1; //借贷期数ID
}

// exec_local 借贷信息
message ReceiptIssuance {
    string      issuanceId      = 1;
    string      accountAddr     = 2;
    int32       status          = 3;
    string      debtId          = 4;
    int32       recordStatus    = 5;
    int32       recordPreStatus = 6;
    int64       index           = 7;
    int64       preIndex        = 8;
}

// exec_local 借贷记录信息
message IssuanceRecord {
    string issuanceId   = 1;
    string addr         = 2;
    string debtId       = 3;
    int64  index        = 4;
}

// exec_local 借贷记录信息列表
message IssuanceRecords {
    repeated IssuanceRecord records = 1;
}

// 根据ID查询一期借贷信息
message ReqIssuanceInfo {
    string issuanceId = 1;
}

// 返回一期借贷信息
message RepIssuanceCurrentInfo {
    int32       status                  = 1;//当期借贷的状态，是否关闭
    int64       totalBalance            = 2; //当期可借贷的总金额(ccny)
    int64       debtCeiling             = 3; //单用户可借出的限额(ccny)
    float       liquidationRatio        = 4; //清算比例
    int64       balance                 = 5; //剩余可借贷金额(ccny)
    int64       collateralValue         = 6; //抵押物总数量(bty)
    int64       debtValue               = 7; //产生的ccny数量
}

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

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

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

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

// 根据用户地址查询发行记录
message ReqIssuanceRecordsByAddr {
    string issuanceId = 1;
    string addr       = 2;
}

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

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

// 精确查找发行记录
message ReqIssuanceDebtInfo {
    string issuanceId = 1;
    string debtId     = 2;
}

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