interface ContractInfoData {
  type: string;
  address?: { street: string; houseNumber: string; postalCode: string; city: string } | null;
  mobileDetails?: {
    phoneNumber: string | null;
    simCards: { phoneNumber: string | null; isMain: boolean }[];
  } | null;
  carInsuranceDetails?: { licensePlate: string | null } | null;
}

export interface ContractTypeInfo {
  label: string;
  value: string;
}

export function getContractTypeInfo(contract: ContractInfoData): ContractTypeInfo | null {
  const { type } = contract;

  if (type === 'ELECTRICITY' || type === 'GAS') {
    const a = contract.address;
    if (!a) return null;
    return {
      label: 'Lieferadresse',
      value: `${a.street} ${a.houseNumber}, ${a.postalCode} ${a.city}`,
    };
  }

  if (type === 'DSL' || type === 'FIBER' || type === 'CABLE') {
    const a = contract.address;
    if (!a) return null;
    return {
      label: 'Anschlussadresse',
      value: `${a.street} ${a.houseNumber}, ${a.postalCode} ${a.city}`,
    };
  }

  if (type === 'MOBILE') {
    const md = contract.mobileDetails;
    if (!md) return null;
    const mainSim = md.simCards?.find((s) => s.isMain && s.phoneNumber);
    const anySim = md.simCards?.find((s) => s.phoneNumber);
    const phone = mainSim?.phoneNumber || anySim?.phoneNumber || md.phoneNumber;
    if (!phone) return null;
    return { label: 'Rufnummer', value: phone };
  }

  if (type === 'CAR_INSURANCE') {
    const plate = contract.carInsuranceDetails?.licensePlate;
    if (!plate) return null;
    return { label: 'Kennzeichen', value: plate };
  }

  return null;
}
