export interface RawResult {
  total_count: number;
  results: RawResultItem[];
}

export interface RawResultItem {
  content: string;
  id: number;
  new: boolean;
  created_at: string;
}
export interface ResultContent {
  name?: string;
  email?: string;
  phone?: string;
  address?: string;
  telegram?: string;
  wechat?: string;
  viber?: string;
  vk?: string;
  skype?: string;
  whatsup?: string;
  messenger?: string;
}

export const defaultResultContent: ResultContent = {
  name: "",
  email: "",
  phone: "",
  address: "",
  telegram: "",
  wechat: "",
  viber: "",
  vk: "",
  skype: "",
  whatsup: "",
  messenger: "",
};

export function rawResultToResult(rawResult: RawResultItem) {
  let content = defaultResultContent;

  try {
    content = JSON.parse(rawResult.content);
  } catch (error) {
    console.warn(
      "Cannot parse result from string, using default config",
      error,
    );
  }

  return {
    ...rawResult,
    content,
  };
}
