classdef (HandleCompatible) VersionMixin
    properties (Hidden, SetAccess = private)
        % CreatedWithVersion version of the pipeline code used to create this object.
        CreatedWithVersion = bioinfo.pipeline.internal.VersionMixin.matlabRelease2Version(bioinfo.pipeline.internal.VersionMixin.CurrentRelease)
    end

    properties (Constant, Access = protected)
        CurrentRelease = matlabRelease;
    end

    methods (Static, Hidden)
        function matlabVersion = version2MatlabRelease(pipelineVersion)
            versionParts = strsplit(pipelineVersion, ".");

            matlabMajorVersion = sprintf("R20%s", versionParts(1));
            if versionParts(2) == "1"
                matlabMinorVersion = "a";
            elseif versionParts(2) == "2"
                matlabMinorVersion = "b";
            end

            matlabUpdateVersion = "";
            if versionParts(3) ~= "0"
                matlabUpdateVersion = sprintf("_update%s", versionParts(3));
            end

            matlabVersion = matlabMajorVersion + matlabMinorVersion + matlabUpdateVersion;
        end

        function version = matlabRelease2Version(release)
            arguments
                release(1,1) matlabRelease
            end

            majVer = extractBetween(release.Release, "R20", "a" | "b");
            if endsWith(release.Release, "a")
                minVer = 1;
            else
                minVer = 2;
            end
            version = sprintf("%s.%d.%d", majVer, minVer, release.Update);
        end

    end
end