import { getKeyValueStore } from "../storage/index.js";
import { isRemoteFileSourceName } from "./source.js";
const STORE_NAME = "file";
// productFile, namedFile
const NAMED_STORE_SUFFIX = "File";
export const NAMED_FILE_TYPE = [
    "product",
    "inventory",
    "service",
    "order",
    "offer"
];
const FILE_NAMES = NAMED_FILE_TYPE;
export function isNamedImportFileType(type) {
    if (!type) {
        return false;
    }
    return type.endsWith("_import");
}
export function isNamedFileType(type) {
    if (!type) {
        return false;
    }
    if (FILE_NAMES.includes(type)) {
        return true;
    }
    if (isRemoteFileSourceName(type)) {
        return true;
    }
    if (!isNamedImportFileType(type)) {
        return false;
    }
    return isRemoteFileSourceName(type.replace(/_import$/, ""));
}
export function getFileStore() {
    return getKeyValueStore(STORE_NAME, {
        counter: false,
    });
}
export function getNamedFileStore(name, prefix) {
    return getKeyValueStore(`${name}${NAMED_STORE_SUFFIX}`, {
        counter: false,
        prefix
    });
}
export function resolveFileStore(file, givenStore) {
    if (givenStore) {
        return givenStore;
    }
    if (isNamedFileType(file.type)) {
        const typedId = file[`${file.type}Id`];
        if (typedId && typeof typedId === "string") {
            return getNamedFileStore(file.type, typedId);
        }
    }
    return getFileStore();
}
//# sourceMappingURL=store.js.map