package common

// CarUpdateProgress represents multi-file update download progress
// If you change this structure and it relevant database entry, please update LogStatusIfNotARepeat
// cloud/modules_go/db/queries/carupdates.go:194
type CarUpdateProgress struct {
	FileCurrent    uint64 `json:"file_current" redis:"file_size"`
	FileTotal      uint64 `json:"file_total" redis:"file_total"`
	PackageCurrent uint64 `json:"package_current" redis:"current_size"`
	PackageTotal   uint64 `json:"package_total" redis:"total_size"`
	InstalledFiles int    `json:"installed" redis:"installed"`
	TotalFiles     int    `json:"total_files" redis:"total_files"`
	CarUpdateID    int64  `json:"car_update_id" redis:"id"`
	ECU            string `json:"ecu" redis:"ecu" validate:"max=100"`
	Status         string `json:"msg" redis:"status,omitempty" validate:"max=1000"`
	Info           string `json:"extra_info,omitempty" redis:"info,omitempty" validate:"max=1000"`
	ErrorCode      int    `json:"err" redis:"errorcode"`
}

func (cu *CarUpdateProgress) Combine(status *CarUpdateProgress) {
	if status == nil {
		return
	}

	cu.PackageCurrent += status.PackageCurrent
	cu.PackageTotal += status.PackageTotal
	cu.InstalledFiles += status.InstalledFiles
	cu.TotalFiles += status.TotalFiles
}
