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

export interface PostGetRegionsReturn extends ResponseType {
  data: { id: number; name: string; flag: string }[];
}

export interface PostGetUserDataReturn extends ResponseType {
  first_visit_year: boolean;
  last_visit_year: boolean;
  no_of_visits: number;
  best_visit_quality: number;
  bbox: any;
  edit_in_trips: 0 | 1;
}

export interface PostGetUserDataDareReturn extends ResponseType {
  visited: boolean;
  first_visit_year: boolean;
  bbox: any;
}

export interface PostGetRegionDataReturn extends ResponseType {
  data: {
    region_name: string;
    region_flag: string;
    visited: boolean;
    best_visit_quality: -1;
    first_visit_year: number;
    last_visit_year: number;
    no_of_visits: number;
    edit_in_trips: 0 | 1;
    photos: {
      title: string;
      id: number;
      user_id: number;
      first_name: string;
      last_name: string;
      avatar: string | null;
    }[];
    users_who_visited_region_count: number;
    users_from_region_count: number;
    users_who_visited_region: string[];
    users_from_region: string[];
    series: {
      series_id: number;
      series_name: string;
      icon: string;
      items: {
        id: number;
        name: string;
        description: string | null;
        new: 0 | 1;
        visited: 0 | 1;
        double_point: 0 | 1;
        visited_double: 0 | 1;
        link: string;
      }[];
    }[];
  };
}

export interface User {
  score_nm: number;
  score_dare: number;
  score_un: number;
  score_unp: number;
  score_tcc: number;
  score_deep: number;
  score_whs: number | null;
  score_kye: number;
  score_tbt: number;
  score_yes: number;
  score_slow: number;
  rank_tbt: number;
  user_id: number;
  avatar: string | null;
  first_name: string;
  last_name: string;
  age: number;
  flag1: string;
  flag2: string | null;
  badge_1281: 0 | 1;
  badge_un: 0 | 1;
  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: 0 | 1;
  badge_tbt: 0 | 1;
  badge_offline: 0 | 1;
  patreon: 0 | 1;
  country: string;
  homebase: number;
  auth: 0 | 1;
  rank: number;
  country_rank: number;
  dod: 0 | 1;
  ukr: 0 | 1;
  badges: 0 | 1;
  arrow_nm: 0 | 1;
  arrow_un: 0 | 1;
  arrow_unp: 0 | 1;
  arrow_dare: 0 | 1;
  arrow_yes: 0 | 1;
  arrow_whs: 0 | 1;
  arrow_tcc: 0 | 1;
  arrow_tbt: 0 | 1;
  arrow_slow: 0 | 1;
  arrow_kye: 0 | 1;
}

export interface PostGetUsersFromRegionDataReturn extends ResponseType {
  data: {
    max_pages: number;
    users: User[];
  };
}

export interface PostGetUsersWhoVisitedDataReturn extends ResponseType {
  data: {
    max_pages: number;
    countries: {
      [key: string]: {
        country: string;
        flag: string;
      };
    };
    users: User[];
  };
}

export interface PostGetListRegionsReturn extends ResponseType {
  data: {
    id: number;
    name: string;
    bbox: any;
    flag: string;
  }[];
}

export const regionsApi = {
  getRegionsWithFlag: () => request.postForm<PostGetRegionsReturn>(API.GET_REGIONS_WITH_FLAGS),
  getUserData: (region_id: number, token: string) =>
    request.postForm<PostGetUserDataReturn>(API.GET_USER_DATA, { region_id, token }),
  getUserDataDare: (dare_id: number, token: string) =>
    request.postForm<PostGetUserDataDareReturn>(API.GET_USER_DATA_DARE, { dare_id, token }),
  getNmRegionData: (id: number, token?: string) =>
    request.postForm<PostGetRegionDataReturn>(API.GET_NM_REGION_DATA, { id, token }),
  getDareRegionData: (id: number, token?: string) =>
    request.postForm<PostGetRegionDataReturn>(API.GET_DARE_REGION_DATA, { id, token }),
  getUsersFromRegion: (id: number, page: number, sort?: string, age?: number) =>
    request.postForm<PostGetUsersFromRegionDataReturn>(API.GET_USERS_FROM_REGION, {
      id,
      page,
      sort,
      age
    }),
  getUsersWhoVisitedRegion: (
    id: number,
    page: number,
    sort?: string,
    age?: number,
    country?: string
  ) =>
    request.postForm<PostGetUsersWhoVisitedDataReturn>(API.GET_USERS_WHO_VISITED_REGION, {
      id,
      page,
      sort,
      age,
      country
    }),
  getUsersWhoVisitedDare: (
    id: number,
    page: number,
    sort?: string,
    age?: number,
    country?: string
  ) =>
    request.postForm<PostGetUsersWhoVisitedDataReturn>(API.GET_USERS_WHO_VISITED_DARE, {
      id,
      page,
      sort,
      age,
      country
    }),
  getListRegions: () => request.postForm<PostGetListRegionsReturn>(API.GET_LIST_REGIONS)
};
