import { defineStore } from 'pinia'
import { useDataStore } from '@/stores/dataStore'
import { useCustomerStore } from '../stores/customerStore'
import { useUsersStore } from '@/stores/usersStore'
import { useGlobalStore } from '@/stores/globalStore'

export const useCustomerService = defineStore('customerService', () => {
  const dataStore = useDataStore()
  const customerStore = useCustomerStore()
  const usersStore = useUsersStore()
  const globalStore = useGlobalStore()

  const GetCustomerOnayIslemTipleri = async () => {
    if (customerStore.onayIslemTipleri.length === 0) {
      let data = await dataStore.dataGet('AppUserOnayDurumuIslemTipi')
      customerStore.onayIslemTipleri = data
    }
  }
  const GetCustomerData = async () => {
    let data: Record<string, any> | any = await dataStore.dataGet(
      'Auth/userbyuserid/' + usersStore.selectedUserId()
    )
    if (data !== 'errorfalse') {
      Object.assign(customerStore.customerForm, data)
      usersStore.userMail = data.email
      globalStore.selCustomerType = data.basvuruTipId
      customerStore.loaded = true
    }
  }

  return { GetCustomerOnayIslemTipleri, GetCustomerData }
})
