// Base
import * as base from './_crud-base'

const path = '/api/vclaim/v1/reference/responsible-doctor'
const name = 'responsible-doctor'

export function getList(params: any = null) {
  let url = path
  if (params?.serviceType) {
    url += `/${params.serviceType}`
    delete params.serviceType
  }
  if (params?.serviceDate) {
    url += `/${params.serviceDate}`
    delete params.serviceDate
  }
  if (params?.specialistCode || (Number(params.specialistCode) === 0)) {
    url += `/${params.specialistCode}`
    delete params.specialistCode
  }
  return base.getList(url, params, name)
}

export async function getValueLabelList(params: any = null): Promise<{ value: string; label: string }[]> {
  let data: { value: string; label: string }[] = []
  const result = await getList(params)
  if (result.success) {
    const resultData = result.body?.response?.list || []
    const resultUnique = [...new Map(resultData.map((item: any) => [item.kode, item])).values()]
    data = resultUnique.map((item: any) => ({
      value: item.kode ? String(item.kode) : '',
      label: `${item.kode} - ${item.nama}`,
    }))
  }
  return data
}
