import { getOrganizerProfile, getVolunteerProfile } from "./profileApi";

/**
 * The commission rate the signed-in publisher is charged (own override, 0%
 * included, else the global default) — the value checkout snapshots.
 *
 * `GET /account/` does not carry it. It is on the publisher's own profile
 * resource: `/organization-profile/` (organizations and volunteer teams) and
 * `/volunteer-profile/` (an approved trainer, shown to the owner only).
 */
export async function getOwnPlatformFee(userType: string | null | undefined): Promise<number | string | null> {
  // Organizations and volunteer teams (session `user_type` "organization" / "voluntary_team")
  // read the organization profile; only an individual (a trainer) reads the volunteer profile.
  const isIndividual = userType === "individual" || userType === "volunteer";
  const response = isIndividual ? await getVolunteerProfile() : await getOrganizerProfile();
  const rate = (response.data as { platform_fee_percentage?: number | string | null } | null | undefined)?.platform_fee_percentage;
  return rate ?? null;
}
