var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import format from "string-format";
import ErrorMessages from "../error-messages";
import { NotSupportedError } from "../errors/not-supported-error";
import Guard from "../guard";
import { Compatibility } from "../models/versionining/compatibility";
export class VersionChecker {
    constructor(client) {
        this.client = client;
        Guard.notNull(client);
    }
    getCompatibility(serverVersion, sdkVersion, minimumSdkVersion) {
        if (this.isDebugVersion(serverVersion) || this.isDebugVersion(sdkVersion)) {
            return Compatibility.Ok;
        }
        if (sdkVersion.smallerThan(minimumSdkVersion)) {
            return Compatibility.SdkOld;
        }
        if (sdkVersion.major > serverVersion.major ||
            (sdkVersion.major === serverVersion.major && sdkVersion.minor > serverVersion.minor)) {
            return Compatibility.SdkNew;
        }
        return Compatibility.Ok;
    }
    compatibilityCheckAsync(requiredVersion) {
        return __awaiter(this, void 0, void 0, function* () {
            const apiInfo = yield this.client.getApiInfoAsync();
            if (apiInfo.fileVersion.smallerThan(requiredVersion) && !this.isDebugVersion(apiInfo.fileVersion)) {
                throw new NotSupportedError(format(ErrorMessages.ContentHubClient.NotSupportedFeature, apiInfo.fileVersion, requiredVersion));
            }
        });
    }
    isCompatibleAsync(requiredVersion) {
        return __awaiter(this, void 0, void 0, function* () {
            const apiInfo = yield this.client.getApiInfoAsync();
            if (apiInfo.fileVersion > requiredVersion || this.isDebugVersion(apiInfo.fileVersion)) {
                return true;
            }
            return false;
        });
    }
    isDebugVersion(version) {
        return version.major <= 1;
    }
}
//# sourceMappingURL=version-checker.js.map