// Third-party Imports
import type { PayloadAction } from '@reduxjs/toolkit'
import { createSlice } from '@reduxjs/toolkit'
import { ProductRecipe } from '../../types/services/productRecipe'

// Type Imports

// Data Imports

const initialState: { currentVariant: any, currentProductRecipe: ProductRecipe } = {
  currentVariant: {},
  currentProductRecipe: {
    id: '',
    organization_id: '',
    outlet_id: null,
    product_id: '',
    variant_id: null,
    ingredient_id: '',
    quantity: 0,
    created_at: '',
    updated_at: '',
    product: {
      ID: '',
      OrganizationID: '',
      CategoryID: '',
      SKU: '',
      Name: '',
      Description: null,
      Price: 0,
      Cost: 0,
      BusinessType: '',
      ImageURL: '',
      PrinterType: '',
      UnitID: null,
      HasIngredients: false,
      Metadata: {},
      IsActive: false,
      CreatedAt: '',
      UpdatedAt: ''
    },
    ingredient: {
      id: '',
      organization_id: '',
      outlet_id: null,
      name: '',
      unit_id: '',
      cost: 0,
      stock: 0,
      is_semi_finished: false,
      is_active: false,
      metadata: {},
      created_at: '',
      updated_at: ''
    }
  }
}

export const productRecipeSlice = createSlice({
  name: 'productRecipe',
  initialState,
  reducers: {
    setProductVariant: (state, action: PayloadAction<any>) => {
      state.currentVariant = action.payload
    },
    resetProductVariant: state => {
      state.currentVariant = initialState.currentVariant
    },
    setProductRecipe: (state, action: PayloadAction<ProductRecipe>) => {
      state.currentProductRecipe = action.payload
    },
    resetProductRecipe: state => {
      state.currentProductRecipe = initialState.currentProductRecipe
    }
  }
})

export const { setProductVariant, resetProductVariant, setProductRecipe, resetProductRecipe } = productRecipeSlice.actions

export default productRecipeSlice.reducer
