/** * Domain model for a Store. * Normalizes location data coming from SIW. */ class Store { constructor(data = {}, storeNumber) { this.number = String(storeNumber || data.store_number || '').trim(); this.name = data.name || data.store_name || `Store ${this.number}`; this.address = data.address || ''; this.address2 = data.address2 || ''; this.address3 = data.address3 || ''; this.city = data.city || ''; this.state = data.state || ''; this.postalCode = data.postal_code || ''; this.countryCode = data.country_code || 'US'; this.phone = data.phone || ''; this.districtId = data.district_id || null; this.regionId = data.region_id || null; } get fullAddress() { const parts = [this.address, this.address2, this.address3].filter(Boolean); const cityState = `${this.city}, ${this.state} ${this.postalCode}`.trim(); return [...parts, cityState, this.phone ? `Phone: ${this.phone}` : ''] .filter(Boolean) .join('\n'); } toSummary() { return `### Store ${this.number} - ${this.name}\n\n**ℹ️ Details**\n${this.fullAddress}\nDistrict ID: ${this.districtId || 'N/A'} Region ID: ${this.regionId || 'N/A'}`; } } function createStore(data, storeNumber) { return new Store(data, storeNumber); } module.exports = { Store, createStore };