"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataPartitionPatternPersistence = void 0;
const internal_1 = require("../../internal");
const copyDataUtils = require("../../Utilities/CopyDataUtils");
const timeUtils = require("../../Utilities/timeUtils");
const utils = require("./utils");
class DataPartitionPatternPersistence {
    /**
     * Creates a new instance from a Data partition pattern type object.
     * @param ctx The context.
     * @param dataObj The object to read for data.
     * @returns A new CdmDataPartitionPatternDefinition instance.
     */
    static fromData(ctx, dataObj) {
        const newPattern = ctx.corpus.MakeObject(internal_1.cdmObjectType.dataPartitionPatternDef, dataObj.name);
        newPattern.rootLocation = dataObj.rootLocation;
        if (dataObj.globPattern) {
            newPattern.globPattern = dataObj.globPattern;
        }
        if (dataObj.regularExpression) {
            newPattern.regularExpression = dataObj.regularExpression;
        }
        if (dataObj.parameters) {
            newPattern.parameters = dataObj.parameters;
        }
        if (dataObj.lastFileStatusCheckTime) {
            newPattern.lastFileStatusCheckTime = new Date(dataObj.lastFileStatusCheckTime);
        }
        if (dataObj.lastFileModifiedTime) {
            newPattern.lastFileModifiedTime = new Date(dataObj.lastFileModifiedTime);
        }
        if (dataObj.explanation) {
            newPattern.explanation = dataObj.explanation;
        }
        if (dataObj.specializedSchema) {
            newPattern.specializedSchema = dataObj.specializedSchema;
        }
        utils.addArrayToCdmCollection(newPattern.exhibitsTraits, utils.createTraitReferenceArray(ctx, dataObj.exhibitsTraits));
        return newPattern;
    }
    static toData(instance, resOpt, options) {
        return {
            name: instance.name,
            lastFileStatusCheckTime: timeUtils.getFormattedDateString(instance.lastFileStatusCheckTime),
            lastFileModifiedTime: timeUtils.getFormattedDateString(instance.lastFileModifiedTime),
            explanation: instance.explanation,
            rootLocation: instance.rootLocation,
            globPattern: instance.globPattern,
            regularExpression: instance.regularExpression,
            parameters: instance.parameters,
            specializedSchema: instance.specializedSchema,
            exhibitsTraits: copyDataUtils.arrayCopyData(resOpt, instance.exhibitsTraits, options)
        };
    }
}
exports.DataPartitionPatternPersistence = DataPartitionPatternPersistence;
//# sourceMappingURL=DataPartitionPatternPersistence.js.map