import { faker } from '@faker-js/faker';
import { nanoid } from '../../nanoid.js';
export class Patch {
    /**
     * Generates a random invitation object.
     * @param init Optional values to be present in the object.
     * @returns Random invitation
     */
    mediaPatchRevision(init = {}) {
        const { id = nanoid(), timestamp = faker.date.recent().getTime(), patch = this.patches(faker.number.int({ min: 1, max: 5 })), version = faker.number.int({ min: 1, max: 1000 }), revert = [], newVersion = version + 1, } = init;
        return {
            id,
            timestamp,
            patch,
            version,
            revert,
            newVersion,
        };
    }
    /**
     * Generates a list of random invitation objects.
     * @param size Number of invitations to generate. Default is 25.
     * @returns List of random invitations
     */
    mediaPatchRevisions(size = 25) {
        const result = [];
        for (let i = 0; i < size; i++) {
            result.push(this.mediaPatchRevision());
        }
        return result;
    }
    /**
     * Generates a random JSON patch operation.
     * @returns A random patch information.
     */
    patch() {
        const type = faker.helpers.arrayElement(['add', 'remove', 'replace', 'move', 'copy', 'test']);
        switch (type) {
            case 'add':
                return this.addPatch();
            case 'remove':
                return this.removePatch();
            case 'replace':
                return this.replacePatch();
            case 'move':
                return this.movePatch();
            case 'copy':
                return this.copyPatch();
            case 'test':
                return this.testPatch();
        }
    }
    patches(size = 25) {
        const result = [];
        for (let i = 0; i < size; i++) {
            result.push(this.patch());
        }
        return result;
    }
    addPatch() {
        return {
            op: 'add',
            path: `/${nanoid()}`,
            value: faker.lorem.word(),
        };
    }
    removePatch() {
        return {
            op: 'remove',
            path: `/${nanoid()}`,
        };
    }
    replacePatch() {
        return {
            op: 'replace',
            path: `/${nanoid()}`,
            value: faker.lorem.word(),
        };
    }
    movePatch() {
        return {
            op: 'move',
            from: `/${nanoid()}`,
            path: `/${nanoid()}`,
        };
    }
    copyPatch() {
        return {
            op: 'copy',
            from: `/${nanoid()}`,
            path: `/${nanoid()}`,
        };
    }
    testPatch() {
        return {
            op: 'test',
            path: `/${nanoid()}`,
            value: faker.lorem.word(),
        };
    }
}
//# sourceMappingURL=Patch.js.map