import { request } from '../../../utils';
import { API } from '../../../types';
import { ResponseType } from '../response-type';

export interface PostGetRanking extends ResponseType {
  data: {
    user_id: number;
    score_dare: number;
    score_nm: number;
    score_un: number;
    score_unp: number;
    score_tcc: number;
    score_deep: number;
    score_whs: number;
    score_kye: number;
    score_tbt: number;
    score_yes: number;
    score_slow: number;
    rank_tbt: number;
    avatar: string;
    first_name: string;
    last_name: string;
    age: number;
    flag1: string;
    flag2: string;
    badge_1281: number;
    badge_un: number;
    badge_un_25: 0 | 1;
    badge_un_50: 0 | 1;
    badge_un_75: 0 | 1;
    badge_un_100: 0 | 1;
    badge_un_150: 0 | 1;
    badge_un_193: 0 | 1;
    badge_premium: 0 | 1;
    badge_supreme: number;
    badge_tbt: number;
    badge_offline: number;
    patreon: number;
    country: string;
    auth: number;
    rank: number;
    country_rank: number;
    dod: number;
    ukr: number;
    badges: number;
    arrow_nm: number;
    arrow_un: number;
    arrow_unp: number;
    arrow_dare: number;
    arrow_yes: number;
    arrow_whs: number;
    arrow_tcc: number;
    arrow_tbt: number;
    arrow_slow: number;
    arrow_kye: number;
  }[];
}

export interface PostGetMaster extends ResponseType {
  data: {
    age: number;
    first: number;
    max: number;
    ranking: {
      user_id: number;
      score_dare: number;
      score_nm: number;
      score_un: number;
      score_unp: number;
      score_tcc: number;
      score_deep: number;
      score_whs: number;
      score_kye: number;
      score_tbt: number;
      score_yes: number;
      score_slow: number;
      rank_tbt: number;
      avatar: string;
      first_name: string;
      last_name: string;
      age: number;
      flag1: string;
      flag2: string;
      badge_1281: number;
      badge_un: number;
      badge_un_25: 0 | 1;
      badge_un_50: 0 | 1;
      badge_un_75: 0 | 1;
      badge_un_100: 0 | 1;
      badge_un_150: 0 | 1;
      badge_un_193: 0 | 1;
      badge_supreme: number;
      badge_tbt: number;
      badge_offline: number;
      patreon: number;
      country: string;
      auth: number;
      rank: number;
      country_rank: number;
      dod: number;
      ukr: number;
      badges: number;
      arrow_nm: number;
      arrow_un: number;
      arrow_unp: number;
      arrow_dare: number;
      arrow_yes: number;
      arrow_whs: number;
      arrow_tcc: number;
      arrow_tbt: number;
      arrow_slow: number;
      arrow_kye: number;
      homebase: number;
    }[];
  };
}

export interface PostGetUNTypes extends ResponseType {
  data: {
    type: number;
    name: string;
  }[];
}

export interface Masters {
  id: number;
  type: number;
  origin: string;
  origin1: string;
  origin2: string;
  full_name: string;
  tbt_username: string;
  born: string;
  final: string | null;
  final_year: string;
  final_country: string;
  age: string;
  personal: string;
  media: string;
  media2: string;
  media3: string;
  wikipedia: string;
  book: string;
  book_url: string;
  book2: string;
  book_url2: string;
  social: string;
  twitter: string;
  instagram: string;
  youtube: string;
  status: number;
  sort: number;
  last_country: string;
  user_id: number | null;
  origin1_flag: string;
  origin2_flag: string | null;
  final_flag: string;
  interviews: string[];
}

export interface YearUNType extends ResponseType {
  data: {
    year: number;
    masters: Masters[];
  }[];
}

export interface CountryUNType extends ResponseType {
  data: {
    country: string;
    code: string;
    masters: Masters[];
    flag: string;
  }[];
}

export interface PostGetUNType extends ResponseType {
  data: {
    data: Masters[];
    start: number;
  };
}

export interface PostGetCountriesRanking extends ResponseType {
  data: { two: string; name: string }[];
}

export const rankingApi = {
  getLimitedRanking: () => request.postForm<PostGetRanking>(API.GET_LIMITED_RANKING),
  getFullRanking: () => request.postForm<PostGetRanking>(API.GET_FULL_RANKING),
  getLpi: () => request.postForm<PostGetRanking>(API.GET_LPI),
  getInHistory: () => request.postForm<PostGetRanking>(API.GET_IN_HISTORY),
  getInMemoriam: () => request.postForm<PostGetRanking>(API.GET_IN_MEMORIAM),
  getUNMastersTypes: () => request.postForm<PostGetUNTypes>(API.GET_UN_MASTERS_TYPES),
  getUNMastersType: (type: number) =>
    request.postForm<PostGetUNType>(API.GET_UN_MASTERS_TYPE, { type }),
  getCountriesRanking: () => request.get<PostGetCountriesRanking>(API.GET_COUNTRIES_RANKING),
  getCountriesRankingLPI: () => request.get<PostGetCountriesRanking>(API.GET_COUNTRIES_RANKING_LPI),
  getCountriesRankingMemoriam: () =>
    request.get<PostGetCountriesRanking>(API.GET_COUNTRIES_RANKING_MEMORIAM),
  getMaster: (country: string, age: number, ranking: string, rows: number, page: number) =>
    request.postForm<PostGetMaster>(API.GET_MASTER, {
      country,
      age,
      ranking,
      rows,
      page
    })
};
