import api from 'src/api'

export const getProviderOpportunities = async (providerId) => {
  try {
    const { data } = await api.get(
      `/custom-schedule-available`,
      {
        params: {
          provider_id: providerId
        }
      }
    )

    return data?.payload || []
  } catch (error) {
    console.error('[API] getProviderOpportunities error:', error)
    return []
  }
}

export const getOpportunityById = async (id) => {
  try {
    const { data } = await api.get(`/custom-schedule/${id}`)
    return data?.payload || null
  } catch (error) {
    console.error('[API] getOpportunityById error:', error)
    return null
  }
}


export const proposalOpportunity = async (scheduleId, providerId) => {
  try {
    const { data } = await api.post(`/custom-schedule/${scheduleId}/propose`, { provider_id: providerId })
    return data.payload || null
  } catch (error) {
    console.error('[API] proposalOpportunity error:', error)
    return null
  }
}

export const refuseOpportunity = async (
  scheduleId,
  providerId
) => {
  try {

    const { data } = await api.post(
      `/custom-schedule/${scheduleId}/refuse-opportunity`,
      {
        provider_id: providerId
      }
    )

    return data?.payload || true

  } catch (error) {
    console.error(
      '[API] refuseOpportunity error:',
      error
    )

    return null
  }
}
