// Third-party Imports
import type { PayloadAction } from '@reduxjs/toolkit'
import { createSlice } from '@reduxjs/toolkit'

// Type Imports

// Data Imports
import { Vendor } from '../../types/services/vendor'

const initialState: { currentVendor: Vendor } = {
  currentVendor: {
    id: '',
    organization_id: '',
    name: '',
    email: '',
    phone_number: '',
    address: '',
    contact_person: '',
    tax_number: '',
    payment_terms: '',
    notes: '',
    is_active: true,
    created_at: '',
    updated_at: ''
  }
}

export const VendorSlice = createSlice({
  name: 'vendor',
  initialState,
  reducers: {
    setVendor: (state, action: PayloadAction<Vendor>) => {
      state.currentVendor = action.payload
    },
    resetVendor: state => {
      state.currentVendor = initialState.currentVendor
    }
  }
})

export const { setVendor, resetVendor } = VendorSlice.actions

export default VendorSlice.reducer
