import { defineStore } from 'pinia'
import { ref, reactive } from 'vue'
import { useValidationStore } from '@/stores/validationStore'
import { useAppUserRoleStore } from '../stores/appUserRoleStore'

export const useAppUserRoleValidationStore = defineStore(
  'appUserRoleValidationStore',
  () => {
    const appUserRoleStore = useAppUserRoleStore()
    const validationStore = useValidationStore()

    const userFormChanged = ref<boolean>(false)
    const isFormValid = ref<boolean>(true)
    const invalidTexts = reactive<Record<string, any>>({})

    const FormCheck = (): boolean => {
      Object.assign(invalidTexts, {})
      validationStore.IsFieldEmpty(
        appUserRoleStore.appUserRoleForm,
        invalidTexts,
        'gorevAdi',
        'Lütfen görev adını giriniz'
      )
      isFormValid.value = Object.keys(invalidTexts).length === 0
      return isFormValid.value
    }

    return {
      userFormChanged,
      isFormValid,
      invalidTexts,
      FormCheck
    }
  }
)
