import { deepMerge } from '@3rapp/common';
import { base, zh_CN, en, Faker } from '@faker-js/faker';
import { Utils } from '@mikro-orm/core';
import { Migrator } from '@mikro-orm/migrations';

import { MikroOrmModuleSyncOptions } from '@mikro-orm/nestjs';
import { SeedManager } from '@mikro-orm/seeder';

export const getBbOptions = <T>(options: MikroOrmModuleSyncOptions) =>
    deepMerge(
        {
            // registerRequestContext: false,
            extensions: [Migrator, SeedManager],
            migrations: {
                disableForeignKeys: false,
                tableName: 'migrations',
                path: Utils.detectTsNode() ? 'src/database/migrations' : 'dist/database/migrations',
            },
            seeder: {
                path: Utils.detectTsNode() ? 'src/database/seeders' : 'dist/database/seeders',
                defaultSeeder: 'DatabaseSeeder',
            },
            entities: ['dist/**/*.entity.js', 'node_modules/@3rapp/**/*.entity.js'],
            entitiesTs: ['src/**/*.entity.ts', 'node_modules/@3rapp/**/*.entity.ts'],

            // highlighter: new SqlHighlighter(),
            // metadataProvider: TsMorphMetadataProvider,
            debug: true,
        } as MikroOrmModuleSyncOptions,
        options,
        'replace',
    ) as T;

const faker = new Faker({
    locale: [zh_CN, en, base],
});
export const getFaker = () => faker;
