/**
 * The saved records the organization account form reads back.
 *
 * Transcribed from `App\Http\Resources\Organization\OrganizationProfileResource`
 * and `OrganizationDocumentResource` (`GET /organization-profile/`); the
 * account half is the same `AccountRecord` the volunteer form uses, since both
 * read `GET /account/`.
 *
 * The whole resource is transcribed, not only the keys one feature reads: the
 * partial version meant three other screens' reads of `platform_fee_percentage`
 * and `is_volunteer_team` typechecked against nothing at all, because the
 * wrapper that returns this record was untyped.
 */
import type { ChoiceDisplay } from "@/lib/choices";

import type { SocialMediaLink } from "./volunteerAccountRecords";

/** One supporting document, as `OrganizationDocumentResource` returns it. */
export interface OrganizationDocument {
  id: number;
  /** An absolute URL, or null when the row has no file. */
  document: string | null;
  uploaded_at: string | null;
}

/** `GET /organization-profile/` — `OrganizationProfileResource`, in full. */
export interface OrganizerProfileRecord {
  /** `organization_profiles.id`. There is no `user` key on this payload. */
  id: number;
  nickname: string | null;
  company_name: string | null;
  /** BE-127 — governmental, computed by type. See the note in
      `commonProfileTypes`: three different fields share this name. */
  is_verified?: boolean | null;
  sector_display: ChoiceDisplay | null;
  organizer_type_display: ChoiceDisplay | null;
  registration_number: string | null;
  license_number: string | null;
  internal_license_document?: string | null;
  instagram_link: string | null;
  whatsapp_link: string | null;
  linkedin_link: string | null;
  facebook_link: string | null;
  twitter_link: string | null;
  /** Already filtered to the rows with a link, so possibly empty but never null. */
  socialMedia: SocialMediaLink[];
  /** `interestPayload()` — the `{ id, name_en, name_ar, interest_type }` shape. */
  interests: OrganizerInterest[];
  /** Soft-deleted rows are filtered out by the resource. */
  documents: OrganizationDocument[];
  badge_info: OrganizerBadgeInfo | null;
  latitude: string | number | null;
  longitude: string | number | null;
  bank_name: string | null;
  bank_account_holder_name: string | null;
  /** Never sent by the current API (BE-187: the IBAN is not serialized); read `bank_account_iban_last4`. */
  bank_account_number?: string | null;
  /** BE-187 — the stored payout IBAN's last four characters, or null when none is on file. */
  bank_account_iban_last4?: string | null;
  /** `hasBankDetails()` — an account is on file (bank, holder and IBAN). */
  has_payout_bank_account?: boolean;
  /** A11 — a holder that does not match the licence name waits for the admin's manual review. */
  bank_holder_review_status?: "not_required" | "pending" | "approved" | "rejected" | null;
  /** True for an individual or association publisher — they must add bank details. */
  requires_bank_details_for_paid_opportunities: boolean;
  /**
   * BE-74. The platform's cut, read here rather than off the opportunity
   * because the publish form has no opportunity yet when the price is set —
   * it is the same `Config::platformFeePercentage()` the opportunity resource
   * uses, so the two can never disagree.
   */
  platform_fee_percentage: number;
  nationality: string | null;
  /** `null`, not `[]`, when the organization has picked no interests. */
  interest_display: ChoiceDisplay[] | null;
  /**
   * Derived, not stored: `organizerType.value_en === 'Volunteer Team'`. So it
   * is driven by the English label of the choice row — renaming that choice
   * silently turns every volunteer team into an ordinary organization.
   */
  is_volunteer_team: boolean;
  organization_hours: number | null;
  learn_opportunity_organized: number | null;
  learn_beneficiaries_count: number | null;
  vol_opportunity_organized: number | null;
  sponsored_count: number | null;
}

/** `ResolvesApiPayloads::interestPayload()`. */
export interface OrganizerInterest {
  id: number;
  name_en: string | null;
  name_ar: string | null;
  interest_type: string | null;
}

/** `badgeInfoPayload()`. Null when the account holds no badge. */
export interface OrganizerBadgeInfo {
  id: number;
  name: string;
  /** `Badge::arabicName()`, sent beside `name` since backend `84a1899`. */
  name_ar?: string | null;
}
