/* eslint-disable unicorn/prefer-module */
import { PlatformServiceName, } from "@limetech/lime-web-components";
import { TestClient, } from "@lundalogik/limeclient.js/testing";
import { readFile } from "node:fs/promises";
export let testClient;
let limetypesFixtures;
let limeobjectsFixtures;
let translationFixtures;
const defaultSession = {
    database: 'dev-app',
    language: 'en',
    active: true,
    admin: true,
    features: {},
    id: '4A2D987FFC5244CD927AE9FE97E325E2DW0000',
    user_id: 2901,
};
beforeAll(async () => {
    const path = `${__dirname}/../src/components/docs-app/fixtures`;
    limetypesFixtures = await readFile(`${path}/limetypes.yaml`, {
        encoding: 'utf8',
    });
    limeobjectsFixtures = await readFile(`${path}/limeobjects.yaml`, {
        encoding: 'utf8',
    });
    translationFixtures = await readFile(`${path}/translations.yaml`, {
        encoding: 'utf8',
    });
});
/**
 *
 * @param session
 */
export function createPlatform(session = {}) {
    testClient = new TestClient({
        fixtures: {
            limetypes: limetypesFixtures,
            limeobjects: limeobjectsFixtures,
            translations: translationFixtures,
        },
        session: Object.assign(Object.assign({}, defaultSession), session),
    });
    return testClient.createPlatform('LimeCRMWebClient');
}
/**
 *
 * @param platform
 * @param limetype
 * @param id
 */
export async function loadLimeObject(platform, limetype, id) {
    const repository = platform.get(PlatformServiceName.LimeObjectRepository);
    await repository.loadObject(limetype, id);
    return repository.getObject(limetype, id);
}
