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

export interface PostGetVisitedIds extends ResponseType {
  ids: number[];
}

export interface PostGetMapDataForRegion extends ResponseType {
  size: number;
  size_humanreadable: string;
  bbox: number[];
  name: string;
}

export interface PostGetLastMapUpdateDate extends ResponseType {
  last_update: string;
}

export interface PostGetSizeForBoundingBox extends ResponseType {
  size: number;
  size_humanreadable: string;
}

export const mapsApi = {
  getVisitedRegionsIds: (token: string, type: 'in' | 'by', year: number, uid: number) =>
    request.postForm<PostGetVisitedIds>(API.GET_VISITED_REGIONS_IDS, { token, type, year, uid }),
  getVisitedCountriesIds: (token: string, type: 'in' | 'by', year: number, uid: number) =>
    request.postForm<PostGetVisitedIds>(API.GET_VISITED_COUNTRIES_IDS, { token, type, year, uid }),
  getVisitedDareIds: (token: string, uid: number) =>
    request.postForm<PostGetVisitedIds>(API.GET_VISITED_DARE_IDS, { token, uid }),
  getVisitedSeriesIds: (token: string) =>
    request.postForm<PostGetVisitedIds>(API.GET_VISITED_SERIES_IDS, { token }),
  getMapDataForRegion: (token: string, region_id: number) =>
    request.postForm<PostGetMapDataForRegion>(API.GET_MAP_DATA_FOR_REGION, { token, region_id }),
  getLastMapUpdateDate: (token: string) =>
    request.postForm<PostGetLastMapUpdateDate>(API.GET_LAST_MAP_UPDATE_DATE, { token }),
  getSizeForBoundingBox: (token: string, bbox_array: number[]) =>
    request.postForm<PostGetSizeForBoundingBox>(API.GET_SIZE_FOR_BOUNDING_BOX, {
      token,
      bbox_array
    })
};
