package org.cryptomator.common.settings;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.Nulls;

import java.nio.file.Path;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
class SettingsJson {

	@JsonProperty("directories")
	@JsonSetter(nulls = Nulls.AS_EMPTY)
	List<VaultSettingsJson> directories = new ArrayList<>();

	@JsonProperty("writtenByVersion")
	String writtenByVersion;

	@JsonProperty("autoCloseVaults")
	boolean autoCloseVaults = Settings.DEFAULT_AUTO_CLOSE_VAULTS;

	@JsonProperty("debugMode")
	boolean debugMode = Settings.DEFAULT_DEBUG_MODE;

	@JsonProperty("theme")
	UiTheme theme = Settings.DEFAULT_THEME;

	@JsonProperty("keychainProvider")
	String keychainProvider = Settings.DEFAULT_KEYCHAIN_PROVIDER;

	@JsonProperty("language")
	String language;

	@JsonProperty("licenseKey")
	String licenseKey;

	@JsonProperty("mountService")
	String mountService;

	@JsonProperty("numTrayNotifications")
	int numTrayNotifications = Settings.DEFAULT_NUM_TRAY_NOTIFICATIONS;

	@JsonProperty("port")
	int port = Settings.DEFAULT_PORT;

	@JsonProperty("showTrayIcon")
	boolean showTrayIcon;

	@JsonProperty("compactMode")
	boolean compactMode;

	@JsonProperty("startHidden")
	boolean startHidden = Settings.DEFAULT_START_HIDDEN;

	@JsonProperty("uiOrientation")
	String uiOrientation = Settings.DEFAULT_USER_INTERFACE_ORIENTATION;

	@JsonProperty("useKeychain")
	boolean useKeychain = Settings.DEFAULT_USE_KEYCHAIN;

	@JsonProperty("windowHeight")
	int windowHeight;

	@JsonProperty("windowWidth")
	int windowWidth;

	@JsonProperty("windowXPosition")
	int windowXPosition;

	@JsonProperty("windowYPosition")
	int windowYPosition;

	@Deprecated(since = "1.7.0")
	@JsonProperty(value = "preferredVolumeImpl", access = JsonProperty.Access.WRITE_ONLY) // WRITE_ONLY means value is "written" into the java object during deserialization. Upvote this: https://github.com/FasterXML/jackson-annotations/issues/233
	String preferredVolumeImpl;

	@JsonProperty("checkForUpdatesEnabled")
	boolean checkForUpdatesEnabled = Settings.DEFAULT_CHECK_FOR_UPDATES;

	@JsonProperty("lastReminderForUpdateCheck")
	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'", timezone = "UTC")
	Instant lastReminderForUpdateCheck = Settings.DEFAULT_TIMESTAMP;

	@JsonProperty("lastSuccessfulUpdateCheck")
	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'", timezone = "UTC")
	Instant lastSuccessfulUpdateCheck = Settings.DEFAULT_TIMESTAMP;

	@JsonProperty("useQuickAccess")
	boolean useQuickAccess = Settings.DEFAULT_USE_QUICKACCESS;

	@JsonProperty("quickAccessService")
	String quickAccessService = Settings.DEFAULT_QUICKACCESS_SERVICE;

	@JsonProperty("previouslyUsedVaultDirectory")
	Path previouslyUsedVaultDirectory;

	@JsonProperty("lastUpdateAttemptedByVersion")
	String lastUpdateAttemptedByVersion;

	@JsonProperty("trustedHosts")
	@JsonSetter(nulls = Nulls.AS_EMPTY)
	Set<String> trustedHosts = new HashSet<>();
}
