import http from '@/utils/http'
import type { InsuranceInfo, InsuranceListParams, InsuranceListResponse, RenewInsuranceParams } from './type'

const { request } = http

// 导出类型定义
export type { InsuranceInfo, InsuranceListParams, InsuranceListResponse, RenewInsuranceParams }

// 新增保险信息
export function createInsurance(data: InsuranceInfo) {
  return request({
    url: '/insurance-info',
    method: 'post',
    data
  })
}

// 查询保险信息列表
export function getInsuranceList(params: InsuranceListParams) {
  return request<InsuranceListResponse>({
    url: '/insurance-info/list',
    method: 'get',
    params
  })
}

// 查询保险信息详情
export function getInsuranceDetail(id: string) {
  return request<InsuranceInfo>({
    url: `/insurance-info/detail/${id}`,
    method: 'get'
  })
}

// 编辑保险信息
export function updateInsurance(id: string, data: InsuranceInfo) {
  return request({
    url: `/insurance-info/${id}`,
    method: 'put',
    data
  })
}

// 删除保险信息
export function deleteInsurance(id: string) {
  return request({
    url: `/insurance-info/${id}`,
    method: 'delete'
  })
}

// 续保
export function renewInsurance(id: string, data: RenewInsuranceParams) {
  return request({
    url: `/insurance-info/renew/${id}`,
    method: 'post',
    data
  })
}

// 批量删除保险信息
export function batchDeleteInsurance(ids: string[]) {
  return request({
    url: '/insurance-info/batch',
    method: 'delete',
    data: { ids }
  })
}

// 导出保险信息
export function exportInsurance(params: InsuranceListParams) {
  return request({
    url: '/insurance-info/export',
    method: 'get',
    params,
    responseType: 'blob'
  })
} 