const { DB } = require('@orbito/api-lib'); const { customAlphabet } = require('nanoid'); const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; const schema = new DB.Schema('shop_config', { apiUrl: { type: 'string', optional: true }, apiKey: { type: 'string', optional: true }, shopName: { type: 'string', optional: true }, versionCode: { type: 'string', optional: true }, // shopPrefix: prefiks używany w uniqueId zamówienia (np. "PL" -> "PL:389218"). // Na razie tylko przechowywany; nie jest jeszcze wpinany w format uniqueId w imporcie. shopPrefix: { type: 'string', optional: true }, // orderStatus: domyślny status gdy brak mapowania PS → Orbito orderStatus: { type: 'ObjectId', optional: true }, // statusMapping: [{ psStateId: 2, orbitoStatusId: "..." }] statusMapping: { type: 'array', items: { type: 'object' }, optional: true, default: [] }, // Podgląd statusów PS (cache do formularza konfiguracji) psStatesPreview: { type: 'string', optional: true, default: '' }, // Lista statusów PS pobrana z API (do UI mapowania) psStates: { type: 'array', items: { type: 'object' }, optional: true, default: [] }, lastOrderId: { type: 'number', optional: true }, createdAt: { type: 'date', default: () => new Date() }, isRemoved: { type: 'boolean', default: false } }); // Pre-validate hook - calculate summary and update derived fields schema.pre('validate', async function(data) { }); schema.post('create', function(data) { // Hook for post-create actions (e.g., emit events, notifications) }); module.exports = schema;