import { computed } from 'vue'
import { useTaxstore } from './taxstore'
import type { AddressOut } from 'src/components/AddressInput.vue'
import type { CommentAttachmentData } from 'src/components/CommentAttachment.vue'

export interface TaxpayerForm {
  prevPreparedByUs: boolean
  prevDeclaration: CommentAttachmentData
  firstName: string
  lastName: string
  birthDate: string
  address: AddressOut
}

// Compatibility wrapper around `taxstore` for code expecting `useTaxpayerStore()`
export const useTaxpayerStore = () => {
  const store = useTaxstore()

  const data = computed(() => store.getTaxpayer())

  function set(partial: Partial<TaxpayerForm>) {
    store.setTaxpayer(partial)
  }

  function replace(payload: TaxpayerForm) {
    store.replaceTaxpayer(payload)
  }

  function reset() {
    store.resetTaxpayer()
  }

  return { data, set, replace, reset }
}
