import request from '@/config/axios'
import type { Dayjs } from 'dayjs';

/** 客户管理信息 */
export interface Management {
          id: number; // id
          customerCode: string; // 客户编码
          customerName: string; // 客户名称
          status?: number; // 状态
          remark: string; // 备注
          afterSalesManager: string; // 售后负责人
          countryCode: string; // 国家编码
          countryName: string; // 国家名称
          provinceCode: string; // 省编码
          provinceName: string; // 省名称
          cityCode: string; // 城市编码
          cityName: string; // 城市名称
          address: string; // 详细地址
          longitude: number; // 经度
          latitude: number; // 纬度
          dbIp: string; // 数据库IP
          dbPort: number; // 数据库端口
          dbUsername: string; // 数据库账号
          dbPassword: string; // 数据库密码
  }

export interface ManagementDbConnectionTestReq {
  id?: number
  dbIp?: string
  dbPort?: number
  dbUsername?: string
  dbPassword?: string
}

// 客户管理 API
export const ManagementApi = {
  // 查询客户管理分页
  getManagementPage: async (params: any) => {
    return await request.get({ url: `/cus/management/page`, params })
  },

  // 查询客户管理详情
  getManagement: async (id: number) => {
    return await request.get({ url: `/cus/management/get?id=` + id })
  },

  // 新增客户管理
  createManagement: async (data: Management) => {
    return await request.post({ url: `/cus/management/create`, data })
  },

  // 修改客户管理
  updateManagement: async (data: Management) => {
    return await request.put({ url: `/cus/management/update`, data })
  },

  // 删除客户管理
  deleteManagement: async (id: number) => {
    return await request.delete({ url: `/cus/management/delete?id=` + id })
  },

  /** 批量删除客户管理 */
  deleteManagementList: async (ids: number[]) => {
    return await request.delete({ url: `/cus/management/delete-list?ids=${ids.join(',')}` })
  },

  // 导出客户管理 Excel
  exportManagement: async (params) => {
    return await request.download({ url: `/cus/management/export-excel`, params })
  },

  // 测试数据库连接
  testDbConnection: async (data: ManagementDbConnectionTestReq) => {
    return await request.post({ url: `/cus/management/test-db-connection`, data })
  },

  // 同步客户数据
  syncData: async (id: number) => {
    return await request.post({ url: `/cus/management/sync-data?id=` + id })
  }
}
