import type { FlowExecCtx } from "@pkg/logic/core/flow.execution.context";
import type { Err } from "@pkg/result";

export async function getFlowExecCtxForRemoteFuncs(
    locals: App.Locals,
): Promise<FlowExecCtx> {
    return {
        flowId: locals.flowId || crypto.randomUUID(),
        userId: locals.user?.id,
        sessionId: locals.session?.id,
    };
}

export function unauthorized(fctx: FlowExecCtx) {
    return {
        data: null,
        error: {
            flowId: fctx.flowId,
            code: "UNAUTHORIZED",
            message: "User not authenticated",
            description: "Please log in",
            detail: "No user ID found in session",
        } as Err,
    };
}
