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

export interface PostGetSettingsReturn extends ResponseType {
  sharing: 0 | 1;
}

export interface PostGetUsersLocationReturn extends ResponseType {
  geojson: GeoJSON.FeatureCollection;
}

export interface PostIsFeatureActiveReturn extends ResponseType {
  active: boolean;
}

export const locationApi = {
  getSettings: (token: string) =>
    request.postForm<PostGetSettingsReturn>(API.GET_LOCATION_SETTINGS, { token }),
  setSettings: (token: string, sharing: 0 | 1) =>
    request.postForm<ResponseType>(API.SET_LOCATION_SETTINGS, { token, sharing }),
  updateLocation: (token: string, lat: number, lng: number) =>
    request.postForm<ResponseType>(API.UPDATE_LOCATION, { token, lat, lng }),
  getUsersLocation: (token: string) =>
    request.postForm<PostGetUsersLocationReturn>(API.GET_USERS_LOCATION, { token }),
  isFeatureActive: (token: string) =>
    request.postForm<PostIsFeatureActiveReturn>(API.IS_FEATURE_ACTIVE, { token })
};
