"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.wrapFormData = wrapFormData;
const _1 = require("../Class/$");
const InvalidKeyPathError_1 = require("../exception/InvalidKeyPathError");
const MethodNotImplementedError_1 = require("../exception/MethodNotImplementedError");
function wrapFormData(formData, system) {
    const _obj = new (class FormData_ extends _1.$ {
        constructor() {
            super(...arguments);
            this.__ = ['J', 'FD'];
        }
        get(name) {
            const data = formData.get(name);
            return Promise.resolve(data);
        }
        set(name, data) {
            formData.set(name, data);
            return;
        }
        delete(name) {
            formData.delete(name);
            return;
        }
        hasKey(name) {
            return formData.has(name);
        }
        keys() {
            const keys = [];
            formData.forEach((value, key) => {
                keys.push(key);
            });
            return keys;
        }
        deepGet(path) {
            if (path.length === 1) {
                return Promise.resolve(formData.get(path[0]));
            }
            throw new InvalidKeyPathError_1.InvalidKeyPathError();
        }
        deepSet(path, data) {
            if (path.length === 1) {
                formData.set(path[0], data);
                return;
            }
            throw new InvalidKeyPathError_1.InvalidKeyPathError();
        }
        deepDelete(path) {
            if (path.length === 1) {
                formData.delete(path[0]);
                return;
            }
            throw new InvalidKeyPathError_1.InvalidKeyPathError();
        }
        deepHas(path) {
            try {
                this.deepGet(path);
                return true;
            }
            catch (err) {
                return false;
            }
        }
        subscribe(path, key, listener) {
            throw new MethodNotImplementedError_1.MethodNotImplementedError();
        }
        append(name, value) {
            formData.append(name, value);
        }
        raw() {
            return formData;
        }
    })(system);
    return _obj;
}
//# sourceMappingURL=FormData.js.map