import { Product } from '../models/Product' ; import { Basket } from '../models/Basket' ; import { generateUid } from '@/infrastructure/uid/uid' ; const hasProduct = ( basket , product ) => basket . items . find ( ( item ) => item . id === product . id ) ; const createBasket = ( product ) => ( { id : generateUid ( ) , items : [ product ] } ) ; const increaseBasket = ( basket , product ) => ( { ... basket , items : [ ... basket . items , product ] } ) ; const addProductToBasket = ( product , basket ? ) : Basket => basket ? hasProduct ( basket , product ) ? basket : increaseBasket ( basket , product ) : createBasket ( product ) ; export const basketService = { addProductToBasket } ;