import { Identifier } from "@nestri/core/id";
import { Session } from "@nestri/core/session/index";

// Simple session creation function using our clean Session types
export function createSession(config: Session.Config): Session.Session {
  const session: Session.Session = {
    description: config.description,
    start: async (payload: any) => {
      console.log(
        `Starting session ${config.description} with payload:`,
        payload,
      );
      // TODO: Implement actual session start logic
      return {
        id: `run_${Date.now()}` as `run_${string}`,
        sessionIdentifier: config.description,
        publicAccessToken: "mock_token",
      };
    },

    startAndWait: (payload: any) => {
      console.log(
        `Starting session ${config.description} and waiting with payload:`,
        payload,
      );
      // TODO: Implement actual session start and wait logic
      return new Promise((resolve) => {
        setTimeout(() => {
          resolve({
            ok: true,
            id: `run_${Date.now()}` as any,
            sessionIdentifier: config.description,
          });
        }, 1000);
      });
    },
  };

  // Store the run function for later execution
  (session as any)._runFunction = config.run;

  return session;
}

export const session = createSession;
