package com.lanyuanxiaoyao.service.web.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.lanyuanxiaoyao.service.common.entity.SyncState;
import com.lanyuanxiaoyao.service.configuration.utils.DatetimeUtil;
import java.time.Instant;

/**
 * @author lanyuanxiaoyao
 * @date 2023-04-26
 */
public class SyncStateVO {
    @JsonIgnore
    private final SyncState syncState;

    private final String sourceStartTimeFromNow;
    private final String sourceCheckpointTimeFromNow;
    private final String sourcePublishTimeFromNow;
    private final String sourceOperationTimeFromNow;
    private final String compactionStartTimeFromNow;
    private final String compactionFinishTimeFromNow;
    private final String compactionStatusTimeFromNow;
    private final String compactionLatestOperationTimeFromNow;

    public SyncStateVO(SyncState syncState) {
        this.syncState = syncState;

        long now = Instant.now().toEpochMilli();
        this.sourceStartTimeFromNow = DatetimeUtil.fromNow(now, this::getSourceStartTime);
        this.sourceCheckpointTimeFromNow = DatetimeUtil.fromNow(now, this::getSourceCheckpointTime);
        this.sourcePublishTimeFromNow = DatetimeUtil.fromNow(now, this::getSourcePublishTime);
        this.sourceOperationTimeFromNow = DatetimeUtil.fromNow(now, this::getSourceOperationTime);
        this.compactionStartTimeFromNow = DatetimeUtil.fromNow(now, this::getCompactionStartTime);
        this.compactionFinishTimeFromNow = DatetimeUtil.fromNow(now, this::getCompactionFinishTime);
        this.compactionStatusTimeFromNow = DatetimeUtil.fromNow(now, this::getCompactionStatusTime);
        this.compactionLatestOperationTimeFromNow = DatetimeUtil.fromNow(now, this::getCompactionLatestOperationTime);
    }

    public String getMessageId() {
        return syncState.getMessageId();
    }

    public Long getSourceStartTime() {
        return syncState.getSourceStartTime();
    }

    public Long getSourceCheckpointTime() {
        return syncState.getSourceCheckpointTime();
    }

    public Long getSourcePublishTime() {
        return syncState.getSourcePublishTime();
    }

    public Long getSourceOperationTime() {
        return syncState.getSourceOperationTime();
    }

    public Long getCompactionStartTime() {
        return syncState.getCompactionStartTime();
    }

    public Long getCompactionFinishTime() {
        return syncState.getCompactionFinishTime();
    }

    public String getCompactionApplicationId() {
        return syncState.getCompactionApplicationId();
    }

    public String getCompactionStatus() {
        return syncState.getCompactionStatus();
    }

    public Long getCompactionStatusTime() {
        return syncState.getCompactionStatusTime();
    }

    public Long getCompactionLatestOperationTime() {
        return syncState.getCompactionLatestOperationTime();
    }

    public String getSourceStartTimeFromNow() {
        return sourceStartTimeFromNow;
    }

    public String getSourceCheckpointTimeFromNow() {
        return sourceCheckpointTimeFromNow;
    }

    public String getSourcePublishTimeFromNow() {
        return sourcePublishTimeFromNow;
    }

    public String getSourceOperationTimeFromNow() {
        return sourceOperationTimeFromNow;
    }

    public String getCompactionStartTimeFromNow() {
        return compactionStartTimeFromNow;
    }

    public String getCompactionFinishTimeFromNow() {
        return compactionFinishTimeFromNow;
    }

    public String getCompactionStatusTimeFromNow() {
        return compactionStatusTimeFromNow;
    }

    public String getCompactionLatestOperationTimeFromNow() {
        return compactionLatestOperationTimeFromNow;
    }
}
