'use strict';
import { createUserResource } from './user-db.js';
import { createUserSetting as createUserSetting$1, createUserSettingDirectlyInDb, tryGetUserSettingByUserId } from './user-settings/user-setting-db.js';
import { createBaseResourceProperties } from '../utils/base-resource-properties.js';
import { tryGetItemByItemName, createItem } from '../items/item-db.js';
import { hash } from '@node-rs/argon2';
import { isRoleExists, getRoleByName } from '../auth/role-db.js';
import { resourceNames } from '../../../fd-toolbox/resources/resource-names.js';
import { getNewUuid } from '../../../fd-toolbox/uuids.js';
import { randomBytes } from 'node:crypto';
import { getUserFeatureToUserIdMap, createUserFeatures } from './user-feature-db.js';
import { getUserSeedModels, createWorkerBot } from './user-mother.js';
import { auths } from '../../../fd-toolbox-core/server/constants/auth-constants.js';
import { publicImages } from '../../../fd-toolbox/constants/public-files.js';
import { fileExtensionsWithoutDot, stringEncodingNames } from '../../../base-repo/app-constants/internal-system-constants.js';
import { createResourceDirectlyInDb } from '../../meta/server/db/db.js';
import { createResource } from '../../meta/server/resources/crud-resources.js';
import { resourceFolders } from '../../../fd-toolbox/constants/resource-folders.js';
import { commonLowerCaseWords } from '../../../base-repo/constants/internal-common-strings.js';

var __defProp=Object['defineProperty'],__name=(_0x37e3d6,_0x1cbbbc)=>__defProp(_0x37e3d6,'name',{'value':_0x1cbbbc,'configurable':!![]});async function seedUsers(){const _0x3f7e69=getUserSeedModels();for(const _0x2e047d of Object['keys'](_0x3f7e69)){const _0x110abe=_0x3f7e69[_0x2e047d],_0x20f143=await createUser(_0x110abe);for(const _0x56a588 of _0x110abe['roles']){await createUserRole(_0x20f143,_0x56a588);}const _0x2fc12b=await createUserSetting(_0x110abe,_0x2e047d);await createUserSetting$1(_0x2fc12b);}}__name(seedUsers,'seedUsers');async function seedWorkerBotDirectlyInDb(){const _0x3efadf=createWorkerBot(),_0x1be5ef=await createUserDirectlyInDb(_0x3efadf);for(const _0x45cc13 of _0x3efadf['roles']){await createUserRoleDirectlyInDb(_0x1be5ef,_0x45cc13);}const _0x259a92=await createUserSetting(_0x3efadf,_0x3efadf['userId']);await createUserSettingDirectlyInDb(_0x259a92);}__name(seedWorkerBotDirectlyInDb,'seedWorkerBotDirectlyInDb');async function seedOtherUsersInfo(_0x3560c1){const _0x292852=getUserSeedModels(),_0x5a2824=await getUserFeatureToUserIdMap();for(const _0x357e24 of Object['keys'](_0x292852)){const _0x56bf34=_0x292852[_0x357e24];let _0x4c938d=_0x5a2824['get'](_0x56bf34['userId']);_0x4c938d??=[],await seedOtherUserInfo(_0x56bf34,_0x3560c1,_0x4c938d,_0x357e24);}}__name(seedOtherUsersInfo,'seedOtherUsersInfo');const seedUserInfoTasks={'dev':resourceFolders['dev'],'help':commonLowerCaseWords['help']};async function seedOtherUserInfo(_0x6aa5b1,_0x5bf761,_0x18c609,_0x45e3c2){await createTask(seedUserInfoTasks['dev'],_0x6aa5b1),await createTask(seedUserInfoTasks['help'],_0x6aa5b1);const _0x28ac9f=await tryGetUserSettingByUserId(_0x6aa5b1['userId']);if(!_0x28ac9f){const _0x415647=await createUserSetting(_0x6aa5b1,_0x45e3c2);await createUserSetting$1(_0x415647);}await createUserFeatures(_0x6aa5b1['userId'],_0x5bf761,_0x18c609);}__name(seedOtherUserInfo,'seedOtherUserInfo');async function createTask(_0x40ac1d,_0x7ea350){const _0x3fb737=_0x7ea350['firstName']+'.'+_0x7ea350['lastName']+'\x20'+_0x40ac1d,_0x41ec3d=await tryGetItemByItemName(_0x7ea350['userId'],_0x3fb737);if(_0x41ec3d)return;const _0x27b8ca={...createBaseResourceProperties(),'content':_0x40ac1d,'name':_0x3fb737,'userId':_0x7ea350['userId']};await createItem(_0x27b8ca);}__name(createTask,'createTask');async function createUserSetting(_0x4f052d,_0x208a52){const _0x3f8a32={...createBaseResourceProperties(getNewUuid()),'userId':_0x4f052d['userId'],'firstName':_0x4f052d['firstName'],'lastName':_0x4f052d['lastName'],'imageUrl':'/'+publicImages['user']+'/'+_0x208a52+'.'+fileExtensionsWithoutDot['webp']};return _0x3f8a32;}__name(createUserSetting,'createUserSetting');async function mapUserSeedModelToUser(_0x417061){const _0x588097={'id':_0x417061['userId'],'firstName':_0x417061['firstName'],'lastName':_0x417061['lastName'],'userId':_0x417061['userId'],'email':_0x417061['email'],'passwordHash':await hash(auths['defaultPwd']),'isDisabled':![],'securityStamp':randomBytes(0x1*0x15d7+0xaab+-0x2062)['toString'](stringEncodingNames['hexEncoding']),'imageUrl':_0x417061['imageUrl'],'homeWorkspaceId':_0x417061['homeWorkspaceId'],'currentWorkspaceId':_0x417061['currentWorkspaceId']};return _0x588097;}__name(mapUserSeedModelToUser,'mapUserSeedModelToUser');async function createUser(_0x4e1fb0){const _0x3364d9=await mapUserSeedModelToUser(_0x4e1fb0);return createUserResource(_0x3364d9);}__name(createUser,'createUser');async function createUserDirectlyInDb(_0x3a75f0){const _0x1fcc8f=await mapUserSeedModelToUser(_0x3a75f0);return createResourceDirectlyInDb(_0x1fcc8f,resourceNames['user']);}__name(createUserDirectlyInDb,'createUserDirectlyInDb');async function userToUserRole(_0x4f143b,_0x4ace24){if(!await isRoleExists(_0x4ace24)||!_0x4f143b)return void(0xbc4+-0xf81+-0x57*-0xb);const _0xd91a2f=await getRoleByName(_0x4ace24),_0x126b32={'id':getNewUuid(),'userId':_0x4f143b['id'],'roleId':_0xd91a2f['id'],'user':_0x4f143b,'role':_0xd91a2f};return _0x126b32;}__name(userToUserRole,'userToUserRole');async function createUserRole(_0x393587,_0x27c22d){const _0x2f9228=await userToUserRole(_0x393587,_0x27c22d);if(!_0x2f9228)return;await createResource(_0x2f9228,resourceNames['userRole']);}__name(createUserRole,'createUserRole');async function createUserRoleDirectlyInDb(_0x13974b,_0x2b3329){const _0x26edf1=await userToUserRole(_0x13974b,_0x2b3329);if(!_0x26edf1)return;await createResourceDirectlyInDb(_0x26edf1,resourceNames['userRole']);}__name(createUserRoleDirectlyInDb,'createUserRoleDirectlyInDb');

export { seedOtherUserInfo, seedOtherUsersInfo, seedUsers, seedWorkerBotDirectlyInDb };
