import { defHttp } from '/@/utils/http/axios'
import {
  ProjectListGetResultModel,
  ProjectListParams,
  ProjectListItem,
  ProjectUpdateOrCreateParams,
  ProjectAccountParams,
  ProjectAccountListResultModal,
  AddOrUpdateProjectAccountParams
} from './model/projectModel'
enum Api {
  GetProjectList = '/backstage/project/list',
  GetProjectDetail = '/backstage/project',
  UpdateProjectDetail = '/backstage/project/save',
  AddProject = '/backstage/project/add',
  GetProjectAccount = '/backstage/account',
  AddProjectAccount = '/backstage/account/create',
  SaveProjectAccount = '/backstage/account/save',
  SyncProjectAccountFormJL = '/backstage/account/sync'
}

/**
 * @description 获取项目列表
 */
export function getProjectList(params: ProjectListParams) {
  return defHttp.post<ProjectListGetResultModel>({
    url: Api.GetProjectList,
    params
  })
}

/**
 * @description 通过id获取项目详情
 */
export function getProjectById(params: { id: string }) {
  return defHttp.get<ProjectListItem>({
    url: Api.GetProjectDetail,
    params
  })
}

/**
 * @description 新增项目
 */
export function addProject(params: ProjectUpdateOrCreateParams) {
  return defHttp.post({
    url: Api.AddProject,
    params
  })
}

/**
 * @description 编辑项目
 */
export function updateProject(params: ProjectUpdateOrCreateParams) {
  return defHttp.post({
    url: Api.UpdateProjectDetail,
    params
  })
}

/**
 * @description 获取项目账号信息列表
 */
export function getProjectAccount(params: ProjectAccountParams) {
  return defHttp.get<ProjectAccountListResultModal>({
    url: Api.GetProjectAccount,
    params
  })
}

/** 新增项目账号 */
export function addProjectAccount(params: AddOrUpdateProjectAccountParams) {
  return defHttp.post({
    url: Api.AddProjectAccount,
    params
  })
}

/** 更新项目账号 */
export function saveProjectAccount(params: AddOrUpdateProjectAccountParams) {
  return defHttp.post({
    url: Api.SaveProjectAccount,
    params
  })
}

/** 同步计量账号 */
export function syncProjectAccountFromJL(params: { id: string }) {
  return defHttp.post({
    url: Api.SyncProjectAccountFormJL,
    params
  })
}
