import { useAxios } from './useAxios'
import type { CommCode } from '@/types/CommCode'

export function useCommCode() {
  const { axiosInstance } = useAxios()
  const getCommCode = async (headId: string): Promise<CommCode[]> => {
    try {
      const response = await axiosInstance(null).get<CommCode[]>('/api/comm-code', { params: { headId: headId } })
      return response.data
    } catch (error) {
      console.error(`common code (${headId}) load failed:`, error)
      throw error
    }
  }

  return {
    getCommCode,
  }
}
