import request from './request'

export interface MaskingRuleItem {
  id: number
  name: string
  level_id?: number
  category_id?: number
  algorithm: string
  params?: Record<string, any>
  is_active: boolean
  description?: string
  level_name?: string
  category_name?: string
}

export function getMaskingRules(params?: { level_id?: number; category_id?: number; page?: number; page_size?: number }) {
  return request.get('/masking/rules', { params })
}

export function createMaskingRule(data: Partial<MaskingRuleItem>) {
  return request.post('/masking/rules', data)
}

export function updateMaskingRule(id: number, data: Partial<MaskingRuleItem>) {
  return request.put(`/masking/rules/${id}`, data)
}

export function deleteMaskingRule(id: number) {
  return request.delete(`/masking/rules/${id}`)
}

export function previewMasking(source_id: number, table_name: string, project_id?: number, limit: number = 20) {
  return request.post('/masking/preview', null, { params: { source_id, table_name, project_id, limit } })
}
