/**
 * 僅保留邀請 stub 等少數 local session 讀寫。
 * 業務 mock seed / HarborStore 已移除。
 */
import { readJson, writeJson } from "../../lib/storage";
import type { MemberStatus } from "../../domain/types";
import { KEYS } from "./keys";

export type SessionState = {
  member: {
    tenant_id: string;
    uid: string;
    email: string;
    display_name: string;
    roles: ("member" | "admin")[];
    bio?: string;
    timezone?: string;
    notify_email?: boolean;
    avatar_url?: string | null;
    email_verified?: boolean;
    email_verified_at?: number | null;
    status?: MemberStatus;
    parent_uid?: string | null;
    invite_code?: string;
  };
  password?: string;
};

export function getSession(): SessionState | null {
  return readJson<SessionState | null>(KEYS.session, null);
}

export function setSession(session: SessionState | null): void {
  if (!session) {
    writeJson(KEYS.session, null);
    return;
  }
  writeJson(KEYS.session, session);
}
