syntax = "proto3";
option go_package = "grpc/kafka_grpc";

enum EmumStatus {
    DELIVERED = 0;
    TIMEOUT = 1;
    FAILED = 2;
}

enum ManifestFileType {
    bootloader = 0;
    software = 1;
    calibration = 2;
    other = 3;
}
  
enum CompatibleTrim {
    EXTREME = 0;
    ULTRA = 1;
    SPORT = 2;
}
  
enum CompatibleDriveSide {
    LEFT_HAND_DRIVE = 0;
    RIGHT_HAND_DRIVE = 1;
}

message GRPC_AttendantPayload {
    string handler = 1;
    oneof Data {
        CarUpdateStatus carUpdateStatus = 2;
        CarUpdateProgress carUpdateProgress = 3;
        FileKeysRequest fileKeyReq = 4;
        ECCKeys keys = 5;
        UpdateData updateApprove = 6;
        VehicleData updateGet = 7;
        UpdateManifest updateManifest = 8;
        Order order = 9;
        MessageStatus messageStatus = 10;
        DTCEntry dtcEntry = 11;
        CarUpdateRequest carUpdateRequest = 12;
    }
}

message CarUpdateStatus {
    map<string, CarECU> ecus = 1;
}

message CarECU {
    string vin = 1;
    string ecu = 2;
    string sw_version = 3;
    string serial_number = 4;
    string hw_version = 5;
    string boot_loader_version = 6;
    string fingerprint = 7;
    string code_data_string = 8;
    string vendor = 9;
    string supplier_sw_version = 10;
    int64 epoch_usec = 11;
    string assy_number = 12;
    optional int64 createdAt = 13;
    optional int64 updatedAt = 14;
}

message CarUpdateProgress {
    uint64 fileCurrent = 1;
    uint64 fileTotal = 2;
    uint64 pkgCurrent = 3;
    uint64 pkgTotal = 4;
    int64 installedFiles = 5;
    int64 totalFiles = 6;
    int64 carUpdateID = 7;
    string ecu = 8;
    string info = 9;
    string status = 10;
    int64 errCode = 11;
}

message FileKeysRequest {
    repeated string fileIDs = 1;
}

message DTCEntry {
    int64 createdAt = 1;
    string vin = 2;
    string ecu = 3;
    uint64 dtc = 4;
    int64 timestamp = 5;
    uint32 speed = 6;
    uint32 mileage = 7;
    uint32 volt = 8;
    string snapshotBase64 = 9;
    uint32 status = 10;
}

message ECCKeys {
    repeated ECCKey eccKeys = 1;
}


message ECCKey {
    string ecu = 1;
    string env = 2;
    optional BineryHex pub_key_level_1 = 3;
    optional BineryHex pub_key_level_2 = 4;
    optional BineryHex pub_key_level_3 = 5;
    optional BineryHex level_1 = 6;
    optional BineryHex level_2 = 7;
    optional BineryHex level_3 = 8;
    optional int64 created = 9;
    optional int64 updated = 10;
}

message BineryHex {
    bytes data = 1;
}

message UpdateData {
    int64 id = 1;
}

message VehicleData {
    string vin = 1;
}

message MessageStatus {
    string messageId = 1;
	EmumStatus status = 2;
}


message UpdateManifest {
    int64 id = 1;
    string name = 2;
    string version = 3;
    string description = 4;
    string release_notes = 5;
    string ecu_list = 6;
    repeated UpdateManifestECU ecu_updates = 7;
    string fingerprint = 8;
    int64 car_update_id = 9;
    bool rollback = 10;
    string type = 11;
    string vod = 12;
    int32 manifest_type = 13;
    optional bool active = 14;
    string country = 15;
    string powertrain = 16;
    string restraint = 17;
    string model = 18;
    string trim = 19;
    int32 year = 20;
    string body_type = 21;
    string sums = 22;
    string env = 23;
    int32 update_duration = 24;
    int32 max_attempts = 25;
    optional int64 created = 26;
    optional int64 updated = 27;
}
  

message UpdateManifestECU {
    int64 id = 1;
    int64 manifest_id = 2;
    string name = 3;
    string version = 4;
    string current_version = 5;
    string hw_version = 6;
    repeated string hw_versions = 7;
    string configuration_mask = 8;
    string configuration = 9;
    bool self_download = 10;
    string mode = 11;
    repeated UpdateManifestFile files = 12;
    repeated UpdateManifestECU rollback = 13;
    ECCKey ecc_keys = 14;
    int32 install_priority = 15;
    optional int64 created = 16;
    optional int64 updated = 17;
}

message UpdateManifestFile {
    string file_id = 1;
    int64 manifest_ecu_id = 2;
    string filename = 3;
    string url = 4;
    uint64 file_size = 5;
    string checksum = 6;
    string type = 7;
    int32 order = 8;
    MemoryRegion write_region = 9;
    MemoryRegion erase_region = 10;
    FileKeyResponse file_key = 11;
    optional bool parsed_file = 12;
    string signature = 13;
    repeated string compatible_trims = 14;
    repeated string compatible_drive_sides = 15;
    optional string created = 16;
    optional string updated = 17;
}
  
message MemoryRegion {
    uint64 offset = 1;
    uint64 length = 2;
}
  
message FileKeyResponse {
    string file_id = 1;
    string key = 2;
    string auth = 3;
    string nonce = 4;
    string error = 5;
}


message FeatureCodes {
    string familyCode = 1;
    string featureCode = 2;
}

message VehicleSpecification {
    string orderId = 1; // OrderIndicator
    string productId = 2; // ProductionPhaseIndicator
    string vehicleId = 3; // VehicleIndicator
    string mfPlant = 4; // ManufacturingPlant
    string modelType = 5; // ModelType
    int64 modelId = 6; // ModelYearIndicator
    int64 modelYear = 7;
    string sn = 8; // SequenceNumber
    int64 version = 9; // VersionDuringModelYear
    string model = 10; // VehicleModel
    string vinPre = 11; // VinPrefix
    string destCon = 12; // DestinationCountry
    repeated FeatureCodes feature = 13; // VehicleFeatures
    int64 date = 14; // ExpectedReferenceDate
    string fOrderId = 15; // FleetOrderIndicator
}

message Order {
    int64 specId = 1;
    int64 orderNo = 2;
    string msgIdentifier = 3;
    VehicleSpecification VehicleSpecification = 4;
}

message CarUpdateRequest {
    int64 car_update_id = 1;
}