import { defineStore } from 'pinia'

export const useValidationStore = defineStore('validation', {
  state: () => ({
    errors: {} as Record<string, string[]>,
  }),
  actions: {
    setErrors(errorResponse: any) {
      if (errorResponse?.statusCode === 422 && errorResponse.errors) {
        this.errors = errorResponse.errors
      } else {
        this.errors = {}
      }
    },
    clearErrors() {
      this.errors = {}
    },
  },
})