export type MemberStatus = 'Member' | 'Visitor' | 'Inactive' | 'Former';

export interface MemberListItemDto {
  id: number;
  firstName_en: string;
  lastName_en: string;
  nickName: string | null;
  firstName_zh: string | null;
  lastName_zh: string | null;
  entity: string | null;
  status: MemberStatus;
  email: string | null;
  phoneCell: string | null;
  joinDate: string | null;
  linkedUserId: string | null;
}

export interface MemberDto extends MemberListItemDto {
  gender: string | null;
  dateOfBirth: string | null;
  baptismDate: string | null;
  baptismChurch: string | null;
  phoneHome: string | null;
  address: string | null;
  city: string | null;
  state: string | null;
  zipCode: string | null;
  country: string;
  photoBlobPath: string | null;
  languagePreference: string;
  notes: string | null;
  familyUnitId: number | null;
  createdAt: string;
  updatedAt: string;
}

export interface CreateMemberRequest {
  firstName_en: string;
  lastName_en: string;
  nickName: string | null;
  firstName_zh: string | null;
  lastName_zh: string | null;
  entity: string | null;
  gender: string | null;
  dateOfBirth: string | null;
  baptismDate: string | null;
  baptismChurch: string | null;
  email: string | null;
  phoneCell: string | null;
  phoneHome: string | null;
  address: string | null;
  city: string | null;
  state: string | null;
  zipCode: string | null;
  country: string;
  status: string;
  languagePreference: string;
  joinDate: string | null;
  notes: string | null;
  familyUnitId: number | null;
}

export type UpdateMemberRequest = CreateMemberRequest;

export interface PagedResult<T> {
  items: T[];
  totalCount: number;
  page: number;
  pageSize: number;
  totalPages: number;
}

export interface MemberQueryParams {
  page?: number;
  pageSize?: number;
  search?: string;
  status?: string;
  hasUser?: boolean;
}

/** Display name: NickName (if present) else FirstName_en, plus LastName_en */
export function memberDisplayName(
  m: Pick<MemberListItemDto, 'nickName' | 'firstName_en' | 'lastName_en' | 'entity'>
): string {
  const legal = `${m.firstName_en} ${m.lastName_en}`.trim();
  const base = (m.nickName && m.nickName !== m.firstName_en)
    ? `${m.nickName} ${m.lastName_en} (${legal})`
    : legal;
  // Append the company / business name so a company-check giver is unambiguous.
  return m.entity ? `${base} · ${m.entity}` : base;
}
