/**
 * The two payloads the volunteer account screen is built from.
 *
 * `GET /account/` → `AccountResource` and `GET /volunteer-profile/` →
 * `VolunteerProfileResource`. Two endpoints, one form, which is why
 * `buildVolunteerAccountInitialValues` merges them — and why it took three
 * `any` parameters before this file existed.
 *
 * Both are read through the axios client, so `normalizeDigitsDeep` has already
 * turned any Eastern Arabic digits back into Western ones.
 */

import type { ChoiceDisplay } from "@/lib/choices";

/** `GET /account/` — `AccountResource::toArray()`. */
export interface AccountRecord {
  /** Dashboard rate, including this account's override. */
  platform_fee_percentage?: number | string;
  id: number;
  profile_pic: string | null;
  /**
   * `users.username` — fixed once chosen. An account whose value is empty or
   * breaks the rule (generated from an e-mail) may choose one once
   * (`Username::mayClaim`, backend `174e828c`).
   */
  username?: string | null;
  first_name: string | null;
  last_name: string | null;
  full_name: string | null;
  email: string | null;
  phone_number: string | null;
  country_code: string | null;
  birth_year: number | null;
  /**
   * Always `null`.
   *
   * The resource emits a literal `'password' => null` so the shape is stable;
   * it is never the stored hash. The form seeds its password field with a single
   * space for that reason, and `password_length` is what the UI shows instead.
   */
  password: null;
  manual_id: string | null;
  user_type: string | null;
  /** How many characters the stored password has — for the masked display. */
  password_length: number | null;
  nationality: string | null;
  residency_status: string | null;
  speaks_arabic: boolean | null;
  /** Read off the *volunteer profile*, so null for an organization. */
  gender_display: ChoiceDisplay | null;
  preferred_language: string | null;
  receive_reminder_emails: boolean;
  do_not_disturb: boolean;
  /** `isApprovedTrainer()` — not the same as a pending request. */
  is_trainer: boolean;
  trainer_status: string | null;
  trainer_types: string[];
  show_real_name: boolean;
  civil_id: string | null;
  passport_number: string | null;
  emergency_contact_name: string | null;
  emergency_contact_phone: string | null;
  emergency_contact_country_code: string | null;
  emergency_contact_civil_id: string | null;
  /** The raw `master_choices` id; the `_display` sibling carries the labels. */
  emergency_contact_relationship: number | null;
  emergency_contact_relationship_display: ChoiceDisplay | null;
}

/** One of the counters the client wants hidden until it holds a real value. */
export interface CounterVisibility {
  volunteer_hours: boolean;
  volunteer_opportunities: boolean;
  development: boolean;
  /** Retired from the profile card; the certificates *tab* is unaffected. */
  certificates: boolean;
  sponsorship: boolean;
}

/** `GET /volunteer-profile/` — `VolunteerProfileResource::toArray()`. */
/**
 * One `socialMedia` row.
 *
 * `ResolvesApiPayloads::socialMediaList()` returns `[]` for a user with no
 * links — never null — and it is **pre-filtered** to the rows that have a
 * link, so an entry with an empty `link` cannot occur.
 */
export interface SocialMediaLink {
  platform: string;
  link: string;
}

export interface VolunteerProfileRecord {
  /** The `volunteer_profiles` row id — **not** the user id. */
  id: number;
  nickname: string | null;
  occupation: string | null;
  /** The form field is called `experience_field`; the payload key is this. */
  experience: string | null;
  health_concerns: string | null;
  is_public: boolean;
  is_verified: boolean;
  gender_display: ChoiceDisplay | null;
  birth_year: number | null;
  instagram_link: string | null;
  whatsapp_link: string | null;
  linkedin_link: string | null;
  facebook_link: string | null;
  website_link: string | null;
  twitter_link: string | null;
  show_real_name: boolean;
  trainer_status: string | null;
  trainer_types: string[];
  is_trainer: boolean;
  trainer_rejected_reason: string | null;
  trainer_has_certificate: boolean;
  /** Last four digits only — the IBAN itself is never returned. */
  trainer_iban_last4: string | null;
  /**
   * `socialMediaList()` — only the platforms with a non-empty link, in a fixed
   * order (instagram, whatsapp, linkedin, facebook, twitter). Already filtered,
   * so a reader never has to skip blanks; an account with no links gets `[]`,
   * which is why the form substitutes one empty row to render against.
   */
  socialMedia: SocialMediaLink[];
  /**
   * `userPayload()` returns `$this->user_id` — a bare integer, not an object.
   * The class doc calls this out because the *picker* resources nest a user
   * object under the same key.
   */
  user: number | null;
  /** Legacy `interests` rows: `interestPayload()`. */
  interests: Array<{
    id: number;
    name_en?: string | null;
    name_ar?: string | null;
    interest_type?: string | null;
  }>;
  /** `masterChoiceCollection` — **null**, not `[]`, when there are none. */
  interest_display: ChoiceDisplay[] | null;
  nationality: string | null;
  speaks_arabic: boolean | null;
  total_volunteer_hours: number;
  total_opportunities: number;
  total_certificates: number;
  opportunities_organized: number;
  current_rank: number | null;
  current_year_hours: number;
  /**
   * The earned badge, through `badgeInfoPayload()` — `null` when there is
   * none.
   *
   * Was `unknown`, so the profile header's `badge_info?.name` read could not
   * be checked at all; `individualProfile` typed its whole input `any`, so
   * nothing noticed. `image` is `url($badge->image)` — absolute — or null for
   * a badge with no file.
   */
  badge_info: { id: number; name: string | null; image: string | null } | null;
  /**
   * BE-137 — **every counter in here is optional, and a missing one means
   * zero.** The API now omits a counter whose value is `0` from this block
   * entirely instead of sending `"total_hours": 0`, so a non-optional number
   * here would be a type that lies about the payload.
   *
   * The flat duplicates above (`total_volunteer_hours`,
   * `total_opportunities`, …) were deliberately left alone by that change and
   * still always arrive, `0` included — which is why they are still required.
   * Read a counter as `statistics?.all_time?.x ?? flatEquivalent ?? 0`, the
   * way `buildProfileStatCards` does.
   */
  statistics: {
    current_year?: { hours?: number; rank?: number | null };
    all_time?: {
      total_hours?: number;
      total_opportunities?: number;
      total_certificates?: number;
      opportunities_organized?: number;
    };
  };
  /** `Y-m-d`. */
  dob: string | null;
  email: string | null;
  civil_id: string | null;
  passport_number: string | null;
  residency_status: string | null;
  receive_reminder_emails: boolean;
  do_not_disturb: boolean;
  phone_number: string | null;
  country_code: string | null;
  emergency_contact_name: string | null;
  emergency_contact_phone: string | null;
  emergency_contact_country_code: string | null;
  emergency_contact_civil_id: string | null;
  emergency_contact_relationship: number | null;
  emergency_contact_relationship_display: ChoiceDisplay | null;
  is_expert: boolean;
  expert_opportunities_count: number;
  /** Development opportunities participated in **or** provided. */
  development_opportunities_count: number;
  volunteer_opportunities_count: number;
  counter_visibility: CounterVisibility;
}
