import { defHttp } from '@/utils/http/axios';
import {  
  AddLayerParams,
  GetLayerListParams,
  AddGeomParams,
  GetGeomParams,
  LoginResultModel, 
  GetUserInfoModel,
  CalTubanAreaModel
} from './model/layerModel';

import { ErrorMessageMode } from '#/axios';

enum Api {
  // Login = '/login',
  // GetUserInfo = '/getUserInfo',
  GetUserInfo = '/api/Check/GetUserProfile',
  AddLayer = "/api/ShpLayerSource/PublishLayer",
  DeleteLayer = "/api/ShpLayerSource/DeleteLayer",
  GetLayerInfo = "/api/ShpLayerSource/Get",
  UpdateLyaer = "/api/ShpLayerSource/UpdateLayer",
  GetLayerList = "/api/ShpLayerSource/LoadPage",
  AddGeom = "/api/ShpLayerSource/SaveShapeData",
  GetGeom = "/api/ShpLayerSource/GetShapeData",
  CalTubanArea = "/api/DroneCaseInfoSingle/CalTubanArea",
  SplitAndCalTubanArea = "/api/DroneCaseInfoSingle/SplitAndCalTubanArea",
  SplitTubanBackYuan = "/api/DroneCaseInfoSingle/SplitTubanBackYuan",
  GetPermCode = '/getPermCode',
  TestRetry = '/testRetry',
  Login = '/api/Check/Login',
  Logout = '/api/Check/Logout',
  GetConfig = "/api/ShpLayerSource/LoadSettingConfig",
  UpdateConfig = "/api/ShpLayerSource/UpdateSettingConfig",
}

/**
 * @description: getUserInfo
 */
export function getUserInfo() {
  return defHttp.get<GetUserInfoModel>({ url: Api.GetUserInfo }, { errorMessageMode: 'none' });
}

export function getPermCode() {
  return defHttp.get<string[]>({ url: Api.GetPermCode });
}

export function doLogout() {
  return defHttp.post({ url: Api.Logout });
}

export function testRetry() {
  return defHttp.get(
    { url: Api.TestRetry },
    {
      retryRequest: {
        isOpenRetry: true,
        count: 5,
        waitTime: 1000,
      },
    },
  );
}

export function addLayer1 () {
    return defHttp.post({ url: Api.Logout });
}

export function addLayer(params: AddLayerParams) {
    return defHttp.post(
        {
        url: Api.AddLayer,
        params,
        }
    );
}
export function getLayerInfo(params){
  return defHttp.get(
    { 
        url: Api.GetLayerInfo,
        params:params
    },
  );
}
export function updateLayer(params: AddLayerParams) {
  return defHttp.post(
      {
        url: Api.UpdateLyaer,
        params,
      }
  );
}

export function getLayerList(params:GetLayerListParams) {
    return defHttp.get(
        { 
            url: Api.GetLayerList,
            params:params
        },
      );
}

export function addGeom(params:AddGeomParams) {
  return defHttp.post(
    {
      url: Api.AddGeom,
      params,
    }
  )
}

export function getGeom(params:GetGeomParams) {
  return defHttp.post(
    {
      url: Api.GetGeom,
      params,
    }
  )
}

export function calTubanArea(params:CalTubanAreaModel){
  return defHttp.post(
    {
      url: Api.CalTubanArea,
      params,
    }
  ) 
}

export function splitAndCalTubanArea(params:CalTubanAreaModel){
  return defHttp.post(
    {
      url: Api.SplitAndCalTubanArea,
      params,
    }
  ) 
}


export function splitTubanBackYuan(params:CalTubanAreaModel){
  return defHttp.post(
    {
      url: Api.SplitTubanBackYuan,
      params,
    }
  ) 
}


export function getConfig(params) {
  return defHttp.get(
    {
      url: Api.GetConfig,
      params,
    }
  )
}

export function updateConfig(params) {
  return defHttp.post(
      {
        url: Api.UpdateConfig,
        params,
      }
  );
}



export function deleteLayer(params) {
  return defHttp.delete(
    {
      url: Api.DeleteLayer+"/"+params,
      params,
    }
  )
}