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

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

export interface PostGetRegionsQeReturn extends ResponseType {
  data: {
    out_regs: {
      id: number;
      flag_1: string;
      flag_2: string;
      region_name: string;
      essential: 0 | 1;
      quality: number;
      year: number;
      last: number;
      visits: number;
    }[];
    out_tcc: {
      id: number;
      flag: string;
      flag2: string;
      name: string;
      visited: number;
    }[];
    out_mtp: {
      mtp_id: number;
      flag: string;
      flag2: string;
      name: string;
      visited: number;
    }[];
  };
}

export interface PostSetNmRegion {
  token: string;
  region: number;
  first: number;
  last: number;
  visits: number;
  quality: number;
}

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

export const regionsApi = {
  getMegaregions: (token: string) =>
    request.postForm<PostGetMegaReturn>(API.GET_MEGAREGIONS, { token }),
  getRegionsQe: (megaregion: number, token: string) =>
    request.postForm<PostGetRegionsQeReturn>(API.GET_REGIONS_QE, { megaregion, token }),
  setNmRegion: (data: PostSetNmRegion) => request.postForm<ResponseType>(API.SET_NM_REGION, data),
  setTCCRegion: (data: PostSetTCCRegion) => request.postForm<ResponseType>(API.SET_TCC_REGION, data)
};
