package com.zt.plat.module.base.service.masterdatasync.dto;

import lombok.Data;

import java.time.LocalDateTime;

/**
 * 物料分类同步执行结果。
 */
@Data
public class MasterDataCategorySyncReport {

    private long processedCategories;
    private long insertedCategories;
    private long updatedCategories;
    private long missingParentReferences;
    private boolean success;
    private String message;
    private LocalDateTime startedAt;
    private LocalDateTime finishedAt;

    public static MasterDataCategorySyncReport start() {
        MasterDataCategorySyncReport report = new MasterDataCategorySyncReport();
        report.setStartedAt(LocalDateTime.now());
        report.setSuccess(false);
        report.setMessage("执行中");
        return report;
    }

    public void markSuccess() {
        this.success = true;
        this.message = "执行成功";
    }

    public void markFailure(String message) {
        this.success = false;
        this.message = message;
    }

    public void finish() {
        this.finishedAt = LocalDateTime.now();
    }

    public void incrementProcessed(long delta) {
        this.processedCategories += delta;
    }

    public void incrementInserted() {
        this.insertedCategories++;
    }

    public void incrementUpdated() {
        this.updatedCategories++;
    }

    public void incrementMissingParent() {
        this.missingParentReferences++;
    }
}
