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

export interface PostGetMegaReturn extends ResponseType {
  data: {
    id: number;
    name: string;
    new: 0 | 1;
  }[];
}

export interface PostGetRegionsDAREReturn extends ResponseType {
  data: {
    id: number;
    name: string;
    essential: 0 | 1;
    flag1: string;
    flag2: string | null;
    visited: string;
    new: 0 | 1;
  }[];
}

export interface PostSetDARERegion {
  token: string;
  region: number;
  visits: 0 | 1;
}

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

export const dareApi = {
  getMegaregionsDare: (token: string) =>
    request.postForm<PostGetMegaReturn>(API.GET_MEGAREGIONS_DARE, { token }),
  getRegionsDare: (megaregion: number, token: string) =>
    request.postForm<PostGetRegionsDAREReturn>(API.GET_REGIONS_DARE, { megaregion, token }),
  setDARERegion: (data: PostSetDARERegion) =>
    request.postForm<ResponseType>(API.SET_DARE_REGION, data),
  getListDare: () => request.postForm<PostGetListDareReturn>(API.GET_LIST_DARE)
};
