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

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

  return {
    getCommCode,
  }
}
