import { Faker, base, en } from '@faker-js/faker';
import Randexp from 'randexp';
import { languageToJavaLanguage } from '../../languages/support/index.js';
class RandexpWithFaker extends Randexp {
    faker;
    constructor(regexp, flags, faker) {
        super(regexp, flags);
        this.max = 5;
        this.faker = faker;
        if (this.faker === undefined) {
            throw new Error('Faker is required');
        }
        this.randInt = (from, to) => {
            return faker.number.int({ min: from, max: to });
        };
    }
}
class FakerWithRandexp extends Faker {
    createRandexp(regexp, flags) {
        return new RandexpWithFaker(regexp, flags, this);
    }
}
export async function createFaker(nativeLanguage = 'en') {
    nativeLanguage = languageToJavaLanguage(nativeLanguage);
    let locale;
    try {
        locale = (await import(`@faker-js/faker`))[nativeLanguage];
    }
    catch (error) {
        locale = (await import('@faker-js/faker')).en;
    }
    const faker = new FakerWithRandexp({
        locale: [locale, base, en],
    });
    faker.createRandexp = (pattern, m) => new RandexpWithFaker(pattern, m, faker);
    return faker;
}
