import { faker } from '@faker-js/faker';
const makeUserData = () => ({
    id: faker.number.int({ min: 1, max: 1000 }),
    name: faker.person.fullName(),
    email: faker.internet.email(),
    password: faker.internet.password(),
    email_verified_at: faker.internet.email(),
    active: faker.datatype.boolean(),
    created_at: faker.date.recent().toISOString(),
    updated_at: faker.date.recent().toISOString(),
});
const applyStates = (result, states, factory) => {
    let updated = { ...result };
    if (states.has('active')) {
        updated = { ...updated, ...factory.getActiveState() };
    }
    if (states.has('inactive')) {
        updated = { ...updated, ...factory.getInactiveState() };
    }
    if (states.has('deleted')) {
        updated = { ...updated, ...factory.getDeletedState() };
    }
    return updated;
};
/**
 * UserFactory
 * Factory for generating test User instances
 */
export const UserFactory = Object.freeze({
    /**
     * Create a new factory instance
     */
    new() {
        let customData = {};
        const states = new Set();
        const factory = {
            /**
             * Set custom data
             */
            data(data) {
                customData = { ...customData, ...data };
                return factory;
            },
            /**
             * Set attribute value
             */
            set(key, value) {
                customData[key] = value;
                return factory;
            },
            /**
             * Apply state
             */
            state(name) {
                states.add(name);
                return factory;
            },
            /**
             * Create multiple instances
             */
            count(n) {
                return Array.from({ length: n }, () => factory.create());
            },
            /**
             * State: Active
             */
            getActiveState() {
                return {
                    active: true,
                    deleted_at: null,
                };
            },
            /**
             * State: Inactive
             */
            getInactiveState() {
                return {
                    active: false,
                };
            },
            /**
             * State: Deleted (soft delete)
             */
            getDeletedState() {
                return {
                    deleted_at: faker.date.past().toISOString(),
                };
            },
            /**
             * Create and return merged result
             */
            create() {
                const result = { ...makeUserData(), ...customData };
                return applyStates(result, states, factory);
            },
        };
        return factory;
    },
});
