import { db } from "@pkg/db"; import type { CreateProductPayload, UpdateProductPayload } from "./data"; import { ProductRepository } from "./repository"; export class ProductUseCases { private repo: ProductRepository; constructor(repo: ProductRepository) { this.repo = repo; } async getAllProducts() { return this.repo.listAllProducts(); } async getProductById(id: number) { return this.repo.getProductById(id); } async createProduct(payload: CreateProductPayload) { return this.repo.createProduct(payload); } async updateProduct(payload: UpdateProductPayload) { return this.repo.updateProduct(payload); } async deleteProduct(id: number) { return this.repo.deleteProduct(id); } async refreshProductLinkId(id: number) { return this.repo.refreshProductLinkId(id); } } export function getProductUseCases() { return new ProductUseCases(new ProductRepository(db)); }