package org.limine.snapper.formats.json1;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.limine.snapper.formats.limine8.LimineKey;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public record ImageDetail(@JsonProperty("limineKey") String limineKey,
                          @JsonProperty("leadingSpaces") String leadingSpaces,
                          @JsonProperty("lineIndex") Integer lineIndex,
                          @JsonProperty("fileName") String fileName,
                          @JsonProperty("fileHashName") String fileHashName,
                          @JsonProperty("espDirPath") String espDirPath, //Deprecated, will be removed in version 2
                          @JsonProperty("dirPath") String dirPath,
                          @JsonProperty("filePathLine") String filePathLine,
                          @JsonProperty("snapshotFilePathLine") String snapshotFilePathLine,
                          @JsonProperty("properties") Map<String, String> properties) {

    /**
     * Custom constructor with default value for properties
     */
    public ImageDetail {
        if (properties == null) {
            properties = new HashMap<>();
        }
        if (dirPath == null) {
            dirPath = espDirPath;
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ImageDetail that = (ImageDetail) o;
        return Objects.equals(fileHashName, that.fileHashName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(fileHashName);
    }

    @JsonIgnore
    public String getSnapshotLine() {
        return LimineKey.replace(limineKey) + " " + LimineKey.uri(properties, this.snapshotFilePathLine().trim());
    }
}
