import {
  Type1,
  Type10,
  Type2,
  Type3,
  Type4,
  Type5,
  Type6,
  Type7,
  Type8,
  Type9
} from 'src/database/statisticsService';

export function isType1(obj: any): obj is Type1 {
  const length = Object.keys(obj).length;

  if (length !== 5) {
    return false;
  }

  return (
    'cnt' in obj && 'country' in obj && 'flag' in obj && 'region_id' in obj && 'region_name' in obj
  );
}

export function isType2(obj: any): obj is Type2 {
  const length = Object.keys(obj).length;

  if (length !== 6) {
    return false;
  }

  return (
    'cnt' in obj &&
    'dare_flag' in obj &&
    'dare_id' in obj &&
    'dare_name' in obj &&
    'mega_id' in obj &&
    'mega_name' in obj
  );
}

export function isType3(obj: any): obj is Type3 {
  const length = Object.keys(obj).length;

  if (length !== 6) {
    return false;
  }

  return (
    'year' in obj &&
    'user' in obj &&
    'cnt' in obj &&
    'first_name' in obj &&
    'last_name' in obj &&
    'flag' in obj
  );
}

export function isType4(obj: any): obj is Type4 {
  const length = Object.keys(obj).length;

  if (length !== 7) {
    return false;
  }

  return (
    'cnt' in obj &&
    'country' in obj &&
    'flag' in obj &&
    'mega_id' in obj &&
    'megaregion' in obj &&
    'region_id' in obj &&
    'region_name' in obj
  );
}

export function isType5(obj: any): obj is Type5 {
  const length = Object.keys(obj).length;

  if (length !== 4) {
    return false;
  }

  return 'cnt' in obj && 'flag' in obj && 'region_id' in obj && 'region_name' in obj;
}

export function isType6(obj: any): obj is Type6 {
  const length = Object.keys(obj).length;

  if (length !== 6) {
    return false;
  }

  return (
    'cnt' in obj &&
    'country' in obj &&
    'country_flag' in obj &&
    'region' in obj &&
    'region_flag' in obj &&
    'region_id' in obj
  );
}

export function isType7(obj: any): obj is Type7 {
  const length = Object.keys(obj).length;

  if (length !== 3) {
    return false;
  }

  return 'cnt' in obj && 'country_name' in obj && 'flag' in obj;
}

export function isType8(obj: any): obj is Type8 {
  const length = Object.keys(obj).length;

  if (length !== 5) {
    return false;
  }

  return (
    'cnt' in obj && 'country' in obj && 'flag' in obj && 'mega_id' in obj && 'mega_name' in obj
  );
}

export function isType9(obj: any): obj is Type9 {
  const length = Object.keys(obj).length;

  if (length !== 5) {
    return false;
  }

  return (
    'flag' in obj &&
    'nation' in obj &&
    'score' in obj &&
    'user_count' in obj &&
    'visited_countries' in obj
  );
}

export function isType10(obj: any): obj is Type10 {
  const length = Object.keys(obj).length;

  if (length !== 7) {
    return false;
  }

  return (
    'cnt' in obj &&
    'flags' in obj &&
    'item_id' in obj &&
    'item_name' in obj &&
    'series_icon' in obj &&
    'series_id' in obj &&
    'series_name' in obj
  );
}
