import { defineStore } from 'pinia'
import { ref } from 'vue'
import { useApi } from '../composables/useApi'
import type { Rider } from '../types/models'

export const useRiderStore = defineStore('rider', () => {
  const { api } = useApi()
  const rider = ref<Rider | null>(null)

  async function fetchRider(id: string) {
    const { data } = await api.get<Rider>(`/rider/profile/${id}`)
    rider.value = data
  }

  async function updateRider(id: string, updates: Partial<Rider>) {
    const { data } = await api.put<Rider>(`/rider/profile/${id}`, updates)
    rider.value = data
  }

  return { rider, fetchRider, updateRider }
})
