import { AxiosRequestConfig } from "axios";
import axiosInstance from "../http/axiosInstance";
import { BASE_URL } from "../constants";
import { Extent } from "ol/extent";
import { IRectCoords } from "../interfaces/map";

const config: AxiosRequestConfig = {
    baseURL: BASE_URL.ems
}

export default class GisService {
    static async getAddress(limit?: number, page?: number) {
        return await axiosInstance.get(`/general/address?limit=${limit || 10}&page=${page || 1}`, config)
    }

    static async uploadOverlay(file: File | null, polygonExtent: Extent | undefined, rectCoords: IRectCoords | undefined) {
        if (file && polygonExtent && rectCoords?.bl && rectCoords?.tl && rectCoords?.tr && rectCoords?.br) {
            const formData = new FormData()
            formData.append('file', file)

            formData.append('extentMinX', polygonExtent[0].toString())
            formData.append('extentMinY', polygonExtent[1].toString())
            formData.append('extentMaxX', polygonExtent[2].toString())
            formData.append('extentMaxY', polygonExtent[3].toString())
            formData.append('blX', rectCoords?.bl[0].toString())
            formData.append('blY', rectCoords?.bl[1].toString())
            formData.append('tlX', rectCoords?.tl[0].toString())
            formData.append('tlY', rectCoords?.tl[1].toString())
            formData.append('trX', rectCoords?.tr[0].toString())
            formData.append('trY', rectCoords?.tr[1].toString())
            formData.append('brX', rectCoords?.br[0].toString())
            formData.append('brY', rectCoords?.br[1].toString())
            
            return await axiosInstance.post(`/tiles/upload`, formData, config)
        }
    }

    //static async updateFigure(object_id: string, )
}