/**
 * VocabularyMasteryItem - Progress item for vocabulary mastery (active flashcards)
 * Weight: 1 point
 * Prerequisites: Word must be discovered first
 */

import ProgressItemInterface from '../interfaces/ProgressItemInterface.js';

class VocabularyMasteryItem extends ProgressItemInterface {
    constructor(word, data) {
        super(
            ProgressItemInterface.TYPES.VOCABULARY_MASTERY,
            `vocab-master-${word}`,
            { word, ...data }
        );
        this.word = word;
        this.data = data;
    }

    /**
     * Validate item data
     * @override
     */
    validate() {
        if (!this.word || typeof this.word !== 'string') {
            throw new Error(`VocabularyMasteryItem: Invalid word - ${this.word}`);
        }
        if (!this.data) {
            throw new Error(`VocabularyMasteryItem: Missing data for word - ${this.word}`);
        }
        return true;
    }

    /**
     * Serialize to JSON
     * @override
     */
    serialize() {
        return {
            ...this._getBaseSerialization(),
            word: this.word,
            data: this.data
        };
    }

    /**
     * Get item weight
     * @override
     */
    getWeight() {
        return ProgressItemInterface.WEIGHTS['vocabulary-mastery'];
    }

    /**
     * Check if can be completed (must be discovered first)
     * @override
     */
    canComplete(userProgress) {
        const discovered = userProgress.discoveredWords || [];
        const mastered = userProgress.masteredWords || [];

        // Must be discovered but not yet mastered
        return discovered.includes(this.word) && !mastered.includes(this.word);
    }
}

export default VocabularyMasteryItem;
