package com.datai.integration.model.domain;

import java.time.LocalDateTime;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 同步进度对象
 * 
 * 用于跟踪 syncObjectData 方法的同步进度，存储在内存中
 * 同步任务完成后立即清除，不保留历史记录
 * 
 * @author datai
 * @date 2026-01-16
 */
@Schema(description = "同步进度对象")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SyncProgress
{
    private static final long serialVersionUID = 1L;

    /** 对象ID */
    @Schema(title = "对象ID")
    private Integer objectId;

    /** 同步类型（FULL/INCREMENTAL） */
    @Schema(title = "同步类型")
    private String syncType;

    /** 总批次数量 */
    @Schema(title = "总批次数量")
    private Integer totalBatches;

    /** 已处理批次数量 */
    @Schema(title = "已处理批次数量")
    private Integer processedBatches;

    /** 当前批次 */
    @Schema(title = "当前批次")
    private Integer currentBatch;

    /** 进度百分比（0-100） */
    @Schema(title = "进度百分比")
    private Integer progressPercentage;

    /** 开始时间 */
    @Schema(title = "开始时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime startTime;

    /** 结束时间 */
    @Schema(title = "结束时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime endTime;

    /** 状态（RUNNING/COMPLETED/FAILED） */
    @Schema(title = "状态")
    private String status;

    /** 错误信息（如果有） */
    @Schema(title = "错误信息")
    private String errorMessage;

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
            .append("objectId", getObjectId())
            .append("syncType", getSyncType())
            .append("totalBatches", getTotalBatches())
            .append("processedBatches", getProcessedBatches())
            .append("currentBatch", getCurrentBatch())
            .append("progressPercentage", getProgressPercentage())
            .append("startTime", getStartTime())
            .append("endTime", getEndTime())
            .append("status", getStatus())
            .append("errorMessage", getErrorMessage())
            .toString();
    }
}
