package com.lanyuanxiaoyao.service.configuration.entity.hudi;

import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.map.ImmutableMap;

/**
 * Hudi Rollback
 *
 * @author lanyuanxiaoyao
 * @date 2023-07-06
 */
public final class HudiRollbackPlan {
    private Integer version;
    private Info instantToRollback;
    private ImmutableList<Request> rollbackRequests;

    public HudiRollbackPlan() {
    }

    public HudiRollbackPlan(Integer version, Info instantToRollback, ImmutableList<Request> rollbackRequests) {
        this.version = version;
        this.instantToRollback = instantToRollback;
        this.rollbackRequests = rollbackRequests;
    }

    public Integer getVersion() {
        return version;
    }

    public Info getInstantToRollback() {
        return instantToRollback;
    }

    public ImmutableList<Request> getRollbackRequests() {
        return rollbackRequests;
    }

    @Override
    public String toString() {
        return "HudiRollbackPlan{" +
                "version=" + version +
                ", instantToRollback=" + instantToRollback +
                ", rollbackRequests=" + rollbackRequests +
                '}';
    }

    public static final class Info {
        private String action;
        private String commitTime;

        public Info() {
        }

        public Info(String action, String commitTime) {
            this.action = action;
            this.commitTime = commitTime;
        }

        public String getAction() {
            return action;
        }

        public String getCommitTime() {
            return commitTime;
        }

        @Override
        public String toString() {
            return "Info{" +
                    "action='" + action + '\'' +
                    ", commitTime='" + commitTime + '\'' +
                    '}';
        }
    }

    public static final class Request {
        private String fileId;
        private String partitionPath;
        private String latestBaseInstant;
        private ImmutableList<String> filesToBeDeleted;
        private ImmutableMap<String, Long> logBlocksToBeDeteled;

        public Request() {
        }

        public Request(String fileId, String partitionPath, String latestBaseInstant, ImmutableList<String> filesToBeDeleted, ImmutableMap<String, Long> logBlocksToBeDeteled) {
            this.fileId = fileId;
            this.partitionPath = partitionPath;
            this.latestBaseInstant = latestBaseInstant;
            this.filesToBeDeleted = filesToBeDeleted;
            this.logBlocksToBeDeteled = logBlocksToBeDeteled;
        }

        public String getFileId() {
            return fileId;
        }

        public String getPartitionPath() {
            return partitionPath;
        }

        public String getLatestBaseInstant() {
            return latestBaseInstant;
        }

        public ImmutableList<String> getFilesToBeDeleted() {
            return filesToBeDeleted;
        }

        public ImmutableMap<String, Long> getLogBlocksToBeDeteled() {
            return logBlocksToBeDeteled;
        }

        @Override
        public String toString() {
            return "Request{" +
                    "fileId='" + fileId + '\'' +
                    ", partitionPath='" + partitionPath + '\'' +
                    ", latestBaseInstant='" + latestBaseInstant + '\'' +
                    ", filesToBeDeleted=" + filesToBeDeleted +
                    ", logBlocksToBeDeteled=" + logBlocksToBeDeteled +
                    '}';
        }
    }
}
