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

export interface PostGetList extends ResponseType {
  data: {
    name: string;
    list: List[];
  }[];
}

export interface PostGetStat extends ResponseType {
  data: {
    url1: string;
    url2: string;
    type: number;
    name: string;
    comment: string;
    ranking: Type1[] | Type2[] | Type3[];
  }[];
}

export interface List {
  name: string;
  url1: string;
  url2?: string;
}

export interface Type1 {
  region_id: number;
  cnt: number;
  region_name: string;
  country: string;
  flag: string;
}

export interface Type2 {
  cnt: number;
  mega_id: number;
  mega_name: string;
  dare_name: string;
  dare_flag: string;
  dare_id: number;
}

export interface Type3 {
  year: number;
  user: number;
  cnt: number;
  first_name: string;
  last_name: string;
  flag: string;
}

export const statisticsApi = {
  getList: (token: string) => request.post<PostGetList>(
      API.GET_LIST,
      {},
      {
        headers: {
          Nmtoken: token
        }
      }
    ),
  getStatistic: (token: string, url1: string, url2: string) =>
    request.postForm<PostGetStat>(
      API.GET_STATISTIC,
      { url1, url2 },
      {
        headers: {
          Nmtoken: token
        }
      }
    )
};
