import { create } from 'zustand'

export interface ProductSummary {
  id: string
  name: string
  code: string | null
  description: string | null
  repo_url: string | null
  definition_of_done: string
  auto_pr: boolean
}

interface ProductsStore {
  products: ProductSummary[]
  setProducts: (products: ProductSummary[]) => void
  addProduct: (product: ProductSummary) => void
  updateProduct: (id: string, patch: Partial<ProductSummary>) => void
}

export const useProductsStore = create<ProductsStore>((set) => ({
  products: [],
  setProducts: (products) => set({ products }),
  addProduct: (product) =>
    set((state) => ({ products: [...state.products, product] })),
  updateProduct: (id, patch) =>
    set((state) => ({
      products: state.products.map((p) => (p.id === id ? { ...p, ...patch } : p)),
    })),
}))
