"use strict";
/*
 * @poppinss/utils
 *
 * (c) Harminder Virk <virk@adonisjs.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.defineStaticProperty = void 0;
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
/**
 * Define static properties on a class with inheritance in play.
 */
function defineStaticProperty(self, BaseClass, { propertyName, defaultValue, strategy, }) {
    if (!self.hasOwnProperty(propertyName)) {
        /**
         * Class is inhering the base class directly and hence we don't have to
         * copy any properties
         */
        if (Object.getPrototypeOf(self.prototype) === BaseClass.prototype || strategy === 'define') {
            Object.defineProperty(self, propertyName, {
                value: defaultValue,
                configurable: true,
                enumerable: true,
                writable: true,
            });
            return;
        }
        /**
         * Class is inherting another sub class. We must copy the values to the self
         * class, otherwise mutating them inside the self class will be reflected
         * on the base class.
         */
        const value = self[propertyName];
        if (value === undefined) {
            Object.defineProperty(self, propertyName, {
                value: defaultValue,
                configurable: true,
                enumerable: true,
                writable: true,
            });
            return;
        }
        Object.defineProperty(self, propertyName, {
            value: typeof strategy === 'function' ? strategy(value) : (0, cloneDeep_1.default)(value),
            configurable: true,
            enumerable: true,
            writable: true,
        });
    }
}
exports.defineStaticProperty = defineStaticProperty;
