'use strict';
import { deleteResource } from '../db/db.js';
import { resourceNames } from '../../../../fd-toolbox/resources/resource-names.js';
import { parseToUtc, getNowUtc } from '../../../../fd-toolbox/dates/date-time.js';
import { createCookie, cookieAttributes } from '../../../../fd-toolbox/server/auth/cookies.js';
import { randomBytes } from 'crypto';
import { millisecondsInSecond } from 'date-fns/constants';
import { sessionCookieName } from './session-validation.js';
import { createResource } from '../resources/crud-resources.js';

var __defProp=Object['defineProperty'],__name=(_0x111aa4,_0x248895)=>__defProp(_0x111aa4,'name',{'value':_0x248895,'configurable':!![]});const sessionTtl=(0x208a+-0x19f8+-0x684)*(-0x10e9+0x234f+-0x124e)*(-0x3b1*0x9+-0x4*-0x213+0x1929)*(0x7c*0x29+-0xddb+-0x1*0x5c5)*(0x9d1*-0x3+-0x729*-0x3+0xbe0);async function createSession(_0x73b135,{homeWorkspaceId:_0x1cf276,currentWorkspaceId:_0x203e1f}){const _0x31c00b=randomBytes(-0xc1c+-0x939*0x1+0x1565)['toString']('base64url'),_0x4328da=parseToUtc(getNowUtc()['getTime']()+sessionTtl);return createResource({'id':_0x31c00b,'userId':_0x73b135,'homeWorkspaceId':_0x1cf276,'currentWorkspaceId':_0x203e1f,'expiresAt':_0x4328da},resourceNames['session']);}__name(createSession,'createSession');async function invalidateSession(_0xc4c719){await deleteResource(_0xc4c719,resourceNames['session']);}__name(invalidateSession,'invalidateSession');function createSessionCookie(_0x421475){return createCookie(sessionCookieName,_0x421475,{[cookieAttributes['maxAge']]:(sessionTtl/millisecondsInSecond)['toString']()});}__name(createSessionCookie,'createSessionCookie');

export { createSession, createSessionCookie, invalidateSession };
