import History from '#models/history' import type { SupplierPricePoint, EbayData } from '#models/history' interface RecordHistoryInput { username: string productId: number dataSources: SupplierPricePoint[] dataEbay: EbayData aiResult?: Record | null } /** * Lưu snapshot dữ liệu mỗi lần lấy về để AI gợi ý giá. */ export default class HistoryService { static async record(input: RecordHistoryInput): Promise { return History.create({ username: input.username, productId: input.productId, dataSources: input.dataSources, dataEbay: input.dataEbay, aiResult: input.aiResult ?? null, }) } static async listForProduct(productId: number, limit = 50) { return History.query() .where('product_id', productId) .orderBy('time', 'desc') .limit(limit) } }