/********************************************************************
 * @author:      Kaven
 * @email:       kaven@wuwenkai.com
 * @website:     http://kavenblog.com
 * @file:        [Kaven-Basic] /src/libs/FilePath.ts
 * @create:      2018-08-31 08:57:22.369
 * @modify:      2019-08-03 21:04:08.560
 * @version:     1.1.22
 * @times:       19
 * @lines:       138
 * @copyright:   Copyright © 2018 Kaven. All Rights Reserved.
 * @description: [description]
 * @license:
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 ********************************************************************/
import KavenBasic from "./KavenBasic";
import { Strings } from "./Strings";
/**
 * @since 1.1.7
 * @version 2018-08-31
 */
var FilePath = /** @class */ (function () {
    function FilePath(folder, name, extension) {
        if (folder === void 0) { folder = Strings.Empty; }
        if (name === void 0) { name = Strings.Empty; }
        if (extension === void 0) { extension = Strings.Empty; }
        this.Folder = folder;
        this.Name = name;
        this.Extension = extension;
    }
    Object.defineProperty(FilePath.prototype, "Path", {
        get: function () {
            return KavenBasic.CombinePath(this.Folder, this.NameWithExtension);
        },
        set: function (val) {
            this.Extension = KavenBasic.GetFileExtension(val);
            this.Folder = KavenBasic.GetBaseDir(val);
            this.Name = KavenBasic.GetFileNameWithoutExtension(val);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(FilePath.prototype, "DynamicPath", {
        get: function () {
            if (this.dynamicPath) {
                return this.dynamicPath;
            }
            if (this.GeneratePath) {
                this.dynamicPath = this.GeneratePath(this.Clone()).Path;
                return this.dynamicPath;
            }
            return this.Path;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(FilePath.prototype, "NameWithExtension", {
        get: function () {
            return "" + this.Name + (this.Extension ? "." + this.Extension : Strings.Empty);
        },
        set: function (val) {
            this.Extension = KavenBasic.GetFileExtension(val);
            this.Name = KavenBasic.GetFileNameWithoutExtension(val);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(FilePath.prototype, "HasDynamicPath", {
        get: function () {
            return this.dynamicPath !== undefined;
        },
        enumerable: true,
        configurable: true
    });
    FilePath.prototype.Clone = function (copyGeneratePath) {
        if (copyGeneratePath === void 0) { copyGeneratePath = false; }
        var clone = new FilePath(this.Folder, this.Name, this.Extension);
        if (copyGeneratePath) {
            clone.GeneratePath = this.GeneratePath;
        }
        return clone;
    };
    FilePath.prototype.TryValid = function () {
        this.Path = KavenBasic.RemoveInvalidCharactersForPath(this.Path);
        return this;
    };
    FilePath.prototype.Reset = function (dynamicPath, extension, name, folder) {
        if (dynamicPath === void 0) { dynamicPath = true; }
        if (extension === void 0) { extension = true; }
        if (name === void 0) { name = true; }
        if (folder === void 0) { folder = false; }
        if (dynamicPath) {
            this.dynamicPath = undefined;
        }
        if (extension) {
            this.Extension = Strings.Empty;
        }
        if (name) {
            this.Name = Strings.Empty;
        }
        if (folder) {
            this.Folder = Strings.Empty;
        }
        return this;
    };
    return FilePath;
}());
export { FilePath };
//# sourceMappingURL=FilePath.js.map