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

const path = '/api/vclaim/v1/monitoring/visit'
const name = 'monitoring-visit'

const dummyResponse = {
  metaData: {
    code: '200',
    message: 'Sukses',
  },
  response: {
    sep: [
      {
        diagnosa: 'K65.0',
        jnsPelayanan: 'R.Inap',
        kelasRawat: '2',
        nama: 'HANIF ABDURRAHMAN',
        noKartu: '0001819122189',
        noSep: '0301R00110170000004',
        noRujukan: '0301U01108180200084',
        poli: null,
        tglPlgSep: '2017-10-03',
        tglSep: '2017-10-01',
      },
      {
        diagnosa: 'I50.0',
        jnsPelayanan: 'R.Inap',
        kelasRawat: '3',
        nama: 'ASRIZAL',
        noKartu: '0002283324674',
        noSep: '0301R00110170000005',
        noRujukan: '0301U01108180200184',
        poli: null,
        tglPlgSep: '2017-10-10',
        tglSep: '2017-10-01',
      },
    ],
  },
}

export async function getList(params: any = null, isDummy: boolean = false) {
  try {
    let url = path
    if (params?.date && params.serviceType) {
      url += `/${params.date}/${params.serviceType}`
    }
    if (params) {
      delete params.date
      delete params.serviceType
    }
    const resp = await base.getList(url, params, name)
    
    // Jika success false, return dummy response
    if (isDummy && (!resp.success || !resp.body?.response)) {
      return {
        success: true,
        body: dummyResponse,
      }
    }
    
    return resp
  } catch (error) {
    // Jika terjadi error, return dummy response
    console.error(`Error fetching ${name}s:`, error)
    return {
      success: true,
      body: dummyResponse,
    }
  }
}
