import { get, post } from '@/utils/request'
import type {
  IBaseResponse,
  IPageResponse,
  IListResponse,
  BaseResponse,
  CameraVendorDTO,
  CameraVendorAddRequest,
  CameraVendorUpdateRequest,
  CameraVendorListRequest
} from '@/types'

// 获取厂家列表 (分页)
export function listCameraVendors(params?: CameraVendorListRequest): Promise<IPageResponse<CameraVendorDTO>> {
  return post('/admin/camera-vendors/list', params || {})
}

// 获取所有启用的厂家（用于下拉选择）
export function listEnabledCameraVendors(): Promise<IListResponse<CameraVendorDTO>> {
  return get('/admin/camera-vendors/enabled')
}

// 获取所有厂家
export function listAllCameraVendors(): Promise<IListResponse<CameraVendorDTO>> {
  return get('/admin/camera-vendors/all')
}

// 获取厂家详情
export function getCameraVendor(id: number): Promise<IBaseResponse<CameraVendorDTO>> {
  return get('/admin/camera-vendors/detail', { id })
}

// 根据代码获取厂家
export function getCameraVendorByCode(code: string): Promise<IBaseResponse<CameraVendorDTO>> {
  return get('/admin/camera-vendors/byCode', { code })
}

// 创建厂家
export function addCameraVendor(data: CameraVendorAddRequest): Promise<IBaseResponse<CameraVendorDTO>> {
  return post('/admin/camera-vendors/create', data)
}

// 更新厂家
export function updateCameraVendor(data: CameraVendorUpdateRequest): Promise<IBaseResponse<CameraVendorDTO>> {
  return post('/admin/camera-vendors/update', data)
}

// 删除厂家
export function deleteCameraVendor(id: number): Promise<BaseResponse> {
  return post('/admin/camera-vendors/delete', undefined, {
    params: { id }
  })
}

// 初始化默认厂家数据
export function initCameraVendors(): Promise<BaseResponse> {
  return post('/admin/camera-vendors/init')
}
