import apiClient from './client'

export interface Share {
  id: string
  dataset_id: string
  dataset_name: string
  mount_point: string
  share_type: 'nfs' | 'smb' | 'both' | 'none'
  nfs_enabled: boolean
  nfs_options?: string
  nfs_clients?: string[]
  smb_enabled: boolean
  smb_share_name?: string
  smb_path?: string
  smb_comment?: string
  smb_guest_ok: boolean
  smb_read_only: boolean
  smb_browseable: boolean
  is_active: boolean
  created_at: string
  updated_at: string
  created_by: string
}

export interface CreateShareRequest {
  dataset_id: string
  nfs_enabled: boolean
  nfs_options?: string
  nfs_clients?: string[]
  smb_enabled: boolean
  smb_share_name?: string
  smb_comment?: string
  smb_guest_ok?: boolean
  smb_read_only?: boolean
  smb_browseable?: boolean
}

export interface UpdateShareRequest {
  nfs_enabled?: boolean
  nfs_options?: string
  nfs_clients?: string[]
  smb_enabled?: boolean
  smb_share_name?: string
  smb_comment?: string
  smb_guest_ok?: boolean
  smb_read_only?: boolean
  smb_browseable?: boolean
  is_active?: boolean
}

export const sharesAPI = {
  listShares: async (): Promise<Share[]> => {
    const response = await apiClient.get<{ shares: Share[] }>('/shares')
    return response.data.shares || []
  },

  getShare: async (id: string): Promise<Share> => {
    const response = await apiClient.get<Share>(`/shares/${id}`)
    return response.data
  },

  createShare: async (data: CreateShareRequest): Promise<Share> => {
    const response = await apiClient.post<Share>('/shares', data)
    return response.data
  },

  updateShare: async (id: string, data: UpdateShareRequest): Promise<Share> => {
    const response = await apiClient.put<Share>(`/shares/${id}`, data)
    return response.data
  },

  deleteShare: async (id: string): Promise<void> => {
    await apiClient.delete(`/shares/${id}`)
  },
}
