package com.ruoyi.file.object;

import java.util.Date;

public final class ProjectState
{
    public String token; // 标识
    public long uploadSize = 0; // 上传字节数
    public long writeSize = 0; // 写入字节数
    public long numUpload = 0; // 上传文件数
    public long numWrite = 0; // 写入文件数
    public long numError = 0; // 处理错误数
    public Date lastUploadTime; // 最近上传时间
    public Date lastWriteTime; // 最近写入时间
    public Date lastErrorTime; // 最近错误时间
    public long maxUploadSize = 0; // 最大上传字节数
    public long maxWriteSize = 0; // 最大写入字节数
    public long maxHandleDuration = 0; // 最长处理时间

    public void AddUploadSize(long uploadSize)
    {
        this.uploadSize += uploadSize;
    }

    public void AddWriteSize(long writeSize)
    {
        this.writeSize += writeSize;
    }

    public void AddNumUpload(long numUpload)
    {
        this.numUpload += numUpload;
    }

    public void AddNumWrite(long numWrite)
    {
        this.numWrite += numWrite;
    }

    public void AddNumError(long numError)
    {
        this.numError += numError;
    }

    public void SetLastUploadTime(Date lastUploadTime)
    {
        this.lastUploadTime = lastUploadTime;
    }

    public void SetLastWriteTime(Date lastWriteTime)
    {
        this.lastWriteTime = lastWriteTime;
    }

    public void SetLastErrorTime(Date lastErrorTime)
    {
        this.lastErrorTime = lastErrorTime;
    }

    public void SetMaxUploadSize(long maxUploadSize)
    {
        if(maxUploadSize > this.maxUploadSize)
            this.maxUploadSize = maxUploadSize;
    }

    public void SetMaxWriteSize(long maxWriteSize)
    {
        if(maxWriteSize > this.maxWriteSize)
            this.maxWriteSize += maxWriteSize;
    }

    public void SetMaxHandleDuration(long maxHandleDuration)
    {
        if(maxHandleDuration > this.maxHandleDuration)
            this.maxHandleDuration += maxHandleDuration;
    }

    public void Sum(ProjectState state)
    {
        uploadSize += state.uploadSize;
        writeSize += state.writeSize;
        numUpload += state.numUpload;
        numWrite += state.numWrite;
        numError += state.numError;
        if(null == lastUploadTime || state.lastUploadTime.after(lastUploadTime))
            lastUploadTime = state.lastUploadTime;
        if(null == lastWriteTime || state.lastWriteTime.after(lastWriteTime))
            lastWriteTime = state.lastWriteTime;
        if(null == lastErrorTime || state.lastErrorTime.after(lastErrorTime))
            lastErrorTime = state.lastErrorTime;
        if(state.maxUploadSize > maxUploadSize)
            maxUploadSize = state.maxUploadSize;
        if(state.maxWriteSize > maxWriteSize)
            maxWriteSize += state.maxWriteSize;
        if(state.maxHandleDuration > maxHandleDuration)
            maxHandleDuration += state.maxHandleDuration;
    }

    public String ToString(String split)
    {
        StringBuilder sb = new StringBuilder();
        sb.append("上传文件大小: ").append(uploadSize);
        sb.append(split);
        sb.append("写入文件大小: ").append(writeSize);
        sb.append(split);
        sb.append("上传文件数: ").append(numUpload);
        sb.append(split);
        sb.append("写入文件数: ").append(numWrite);
        sb.append(split);
        sb.append("上传错误数: ").append(numError);
        sb.append(split);
        sb.append("最近上传时间: ").append(lastUploadTime);
        sb.append(split);
        sb.append("最近写入时间: ").append(lastWriteTime);
        sb.append(split);
        sb.append("最近错误时间: ").append(lastErrorTime);
        sb.append(split);
        sb.append("最大上传文件大小: ").append(maxUploadSize);
        sb.append(split);
        sb.append("最大写入文件大小: ").append(maxWriteSize);
        sb.append(split);
        sb.append("最大处理间隔: ").append(maxHandleDuration);
        return sb.toString();
    }

    public ProjectState() {}

    public ProjectState(String token)
    {
        this.token = token;
    }
}
