/** * Domain model for Store Health Report. * Encapsulates score, issues, and summary generation. */ class HealthReport { constructor(storeNumber, storeName = 'Unknown Store') { this.storeNumber = storeNumber; this.storeName = storeName; this.overallScore = 100; this.issues = []; this.sections = []; } deduct(points, reason) { this.overallScore = Math.max(0, this.overallScore - points); if (reason) { this.issues.push(reason); } } addSection(title, content) { this.sections.push({ title, content }); } addIssue(issue) { if (issue && !this.issues.includes(issue)) { this.issues.push(issue); } } finalize() { this.overallScore = Math.round(this.overallScore); const statusEmoji = this.overallScore >= 90 ? '🟢' : this.overallScore >= 70 ? '🟡' : '🔴'; const statusText = this.overallScore >= 90 ? 'Good' : this.overallScore >= 70 ? 'Fair' : 'Needs Attention'; let summary = `**📊 Store ${this.storeNumber} Health Summary - ${this.storeName}**\n\n`; this.sections.forEach(section => { summary += section.content + '\n'; }); summary += `\n**Overall Status**: ${statusEmoji} ${statusText} (${this.overallScore}% healthy)\n\n`; if (this.issues.length > 0) { summary += `**⚠️ Issues Detected**\n`; this.issues.forEach(issue => (summary += `- ${issue}\n`)); } else { summary += `**✅ No major issues detected**\n`; } this.summary = summary; return this; } toJSON() { return { storeNumber: this.storeNumber, storeName: this.storeName, overallScore: this.overallScore, issues: [...this.issues], summary: this.summary, }; } } function createHealthReport(storeNumber, storeName) { return new HealthReport(storeNumber, storeName); } module.exports = { HealthReport, createHealthReport };