/**
 * ProgressItemInterface - Strict interface for all progress items
 * ALL concrete items MUST implement these methods or app refuses to start
 */

import StrictInterface from './StrictInterface.js';

class ProgressItemInterface extends StrictInterface {
    // Item type constants
    static TYPES = {
        VOCABULARY_DISCOVERY: 'vocabulary-discovery',
        VOCABULARY_MASTERY: 'vocabulary-mastery',
        PHRASE: 'phrase',
        DIALOG: 'dialog',
        TEXT: 'text',
        AUDIO: 'audio',
        IMAGE: 'image',
        GRAMMAR: 'grammar'
    };

    // Weight constants (as defined in CLAUDE.md)
    // Note: 1 vocab = 2 points total (discovery + mastery)
    // Other items are 3x+ more valuable to show realistic progress
    static WEIGHTS = {
        'vocabulary-discovery': 1,
        'vocabulary-mastery': 1,
        'phrase': 6,        // 3x vocab
        'dialog': 12,       // 6x vocab (complex)
        'text': 15,         // 7.5x vocab (most complex)
        'audio': 12,        // 6x vocab
        'image': 6,         // 3x vocab
        'grammar': 6        // 3x vocab
    };

    constructor(type, id, metadata = {}) {
        super(`${type}Item`);

        // Validate type
        const validTypes = Object.values(ProgressItemInterface.TYPES);
        if (!validTypes.includes(type)) {
            throw new Error(`Invalid progress item type: ${type}. Must be one of: ${validTypes.join(', ')}`);
        }

        this.type = type;
        this.id = id;
        this.metadata = metadata;
        this.completedAt = null;
    }

    /**
     * Define abstract methods that MUST be implemented
     * @override
     */
    _getAbstractMethods() {
        return ['validate', 'serialize', 'getWeight', 'canComplete'];
    }

    /**
     * ⚠️ MUST IMPLEMENT - Validate item data
     * @returns {boolean} - True if valid
     * @throws {Error} - If validation fails
     */
    validate() {
        this._throwImplementationError('validate');
    }

    /**
     * ⚠️ MUST IMPLEMENT - Serialize to JSON
     * @returns {Object} - Serialized item
     */
    serialize() {
        this._throwImplementationError('serialize');
    }

    /**
     * ⚠️ MUST IMPLEMENT - Get item weight for progress calculation
     * @returns {number} - Weight value
     */
    getWeight() {
        this._throwImplementationError('getWeight');
    }

    /**
     * ⚠️ MUST IMPLEMENT - Check if item can be completed based on prerequisites
     * @param {Object} userProgress - Current user progress state
     * @returns {boolean} - True if prerequisites are met
     */
    canComplete(userProgress) {
        this._throwImplementationError('canComplete');
    }

    /**
     * Mark item as completed
     * @param {string} timestamp - ISO timestamp
     */
    markCompleted(timestamp = new Date().toISOString()) {
        this.completedAt = timestamp;
    }

    /**
     * Check if item is completed
     * @returns {boolean}
     */
    isCompleted() {
        return this.completedAt !== null;
    }

    /**
     * Get base serialization (common to all items)
     * @protected
     */
    _getBaseSerialization() {
        return {
            type: this.type,
            id: this.id,
            metadata: this.metadata,
            completedAt: this.completedAt
        };
    }
}

export default ProgressItemInterface;
