'use strict';
import { toolboxUserConstants } from '../../meta/constants/toolbox-users.js';
import { createUserResource } from './user-db.js';
import { createError } from '../../../fd-toolbox/errors/errors.js';
import { getUserId } from '../../meta/server/auth/users/current-user-id-provider.js';
import { toolboxErrorMessages } from '../../../fd-toolbox/constants/toolbox-error-messages-constants.js';
import { resourceNames } from '../../../fd-toolbox/resources/resource-names.js';
import { getNewUuid } from '../../../fd-toolbox/uuids.js';
import { randomBytes } from 'crypto';
import { hash } from '@node-rs/argon2';
import { hasPermission } from '../../meta/server/permission/permission-checker.js';
import { crudActions } from '../../../fd-toolbox/enums/enums.js';
import { stringEncodingNames } from '../../../base-repo/app-constants/internal-system-constants.js';

var __defProp=Object['defineProperty'],__name=(_0x1b1f58,_0x38dea9)=>__defProp(_0x1b1f58,'name',{'value':_0x38dea9,'configurable':!![]});async function createUser(_0x3ae1db,_0x300641,_0x42da6e=!![]){const _0x236ba3=await getUserId(),_0x48c8b0=_0x236ba3===toolboxUserConstants['workerBotId']||await hasPermission(resourceNames['user'],crudActions['create'],_0x236ba3);if(!_0x48c8b0)throw createError(toolboxErrorMessages['noPermissionToCreateUser']);const _0x2273ee={'id':_0x300641??getNewUuid(),'userId':_0x300641??_0x236ba3,'firstName':_0x3ae1db['firstName']??'','lastName':_0x3ae1db['lastName']??'','email':_0x3ae1db['email'],'passwordHash':await hash(_0x3ae1db['password']),'isDisabled':![],'securityStamp':randomBytes(0x93*0x43+-0x17e4+-0xe75)['toString'](stringEncodingNames['hexEncoding']),'homeWorkspaceId':_0x3ae1db['homeWorkspaceId'],'currentWorkspaceId':_0x3ae1db['currentWorkspaceId']},_0x551d62=await createUserResource(_0x2273ee),_0x4452fb=!!_0x551d62['id'],_0x4c2532={'isSuccess':_0x4452fb,'userFriendlyMessage':''};if(!_0x4452fb){_0x4c2532['userFriendlyMessage']=toolboxErrorMessages['failedToCreateUser'];if(_0x42da6e)throw createError(toolboxErrorMessages['userCreationFailedWithReason']['replace']('{0}',_0x4c2532['userFriendlyMessage']));}return _0x4c2532;}__name(createUser,'createUser');

export { createUser };
