// api.ts から分割（挙動不変）: ユーザー・組織。
import { BASE } from './client';

export interface UserOrg {
  orgId: string;
  orgName: string;
  fetchedAt: string;
}

export async function fetchMyOrgs(): Promise<UserOrg[]> {
  const res = await fetch('/api/users/me/orgs');
  if (!res.ok) return [];
  const { orgs } = (await res.json()) as { orgs: Array<{ orgId: string; orgName: string; fetchedAt: string }> };
  return orgs;
}

export interface PickableUser {
  id: string;
  name: string | null;
  email: string | null;
  avatarUrl: string | null;
}

export async function fetchPickableUsers(): Promise<PickableUser[]> {
  const res = await fetch(`${BASE}/users/pickable`);
  if (!res.ok) return [];
  return (await res.json()) as PickableUser[];
}
