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

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

/**
 * @author lanyuanxiaoyao
 * @date 2023-07-06
 */
public final class HudiCleanerPlan {
    private Integer version;
    private String policy;
    private Instant earliestInstantToRetain;
    private ImmutableMap<String, ImmutableList<Info>> filePathsToBeDeletedPerPartition;
    private ImmutableMap<String, ImmutableList<String>> filesToBeDeletedPerPartition;
    private ImmutableList<String> partitionsToBeDeleted;

    public HudiCleanerPlan() {
    }

    public HudiCleanerPlan(Integer version, String policy, Instant earliestInstantToRetain, ImmutableMap<String, ImmutableList<Info>> filePathsToBeDeletedPerPartition, ImmutableMap<String, ImmutableList<String>> filesToBeDeletedPerPartition, ImmutableList<String> partitionsToBeDeleted) {
        this.version = version;
        this.policy = policy;
        this.earliestInstantToRetain = earliestInstantToRetain;
        this.filePathsToBeDeletedPerPartition = filePathsToBeDeletedPerPartition;
        this.filesToBeDeletedPerPartition = filesToBeDeletedPerPartition;
        this.partitionsToBeDeleted = partitionsToBeDeleted;
    }

    public Integer getVersion() {
        return version;
    }

    public String getPolicy() {
        return policy;
    }

    public Instant getEarliestInstantToRetain() {
        return earliestInstantToRetain;
    }

    public ImmutableMap<String, ImmutableList<Info>> getFilePathsToBeDeletedPerPartition() {
        return filePathsToBeDeletedPerPartition;
    }

    public ImmutableMap<String, ImmutableList<String>> getFilesToBeDeletedPerPartition() {
        return filesToBeDeletedPerPartition;
    }

    public ImmutableList<String> getPartitionsToBeDeleted() {
        return partitionsToBeDeleted;
    }

    @Override
    public String toString() {
        return "HudiCleanerPlan{" +
                "version=" + version +
                ", policy='" + policy + '\'' +
                ", earliestInstantToRetain=" + earliestInstantToRetain +
                ", filePathsToBeDeletedPerPartition=" + filePathsToBeDeletedPerPartition +
                ", filesToBeDeletedPerPartition=" + filesToBeDeletedPerPartition +
                ", partitionsToBeDeleted=" + partitionsToBeDeleted +
                '}';
    }

    public static final class Instant {
        private String action;
        private String state;
        private String timestamp;

        public Instant() {
        }

        public Instant(String action, String state, String timestamp) {
            this.action = action;
            this.state = state;
            this.timestamp = timestamp;
        }

        public String getAction() {
            return action;
        }

        public String getState() {
            return state;
        }

        public String getTimestamp() {
            return timestamp;
        }

        @Override
        public String toString() {
            return "Instant{" +
                    "action='" + action + '\'' +
                    ", state='" + state + '\'' +
                    ", timestamp='" + timestamp + '\'' +
                    '}';
        }
    }

    public static final class Info {
        private String filePath;
        private Boolean isBootstrapBaseFile;

        public Info() {
        }

        public Info(String filePath, Boolean isBootstrapBaseFile) {
            this.filePath = filePath;
            this.isBootstrapBaseFile = isBootstrapBaseFile;
        }

        public String getFilePath() {
            return filePath;
        }

        public Boolean getBootstrapBaseFile() {
            return isBootstrapBaseFile;
        }

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