import { ConfigManager } from '../../config/config-manager.js';
export class DevelopmentDataStore {
    store;
    configManager;
    MODULE_NAME = 'development';
    DATA_FILE = 'development.json';
    constructor(configManager) {
        this.configManager = configManager || new ConfigManager();
        this.store = {
            features: {},
            sessions: {},
            config: {
                enforceTestFirst: true,
                minimumTestCoverage: 80,
                requireTestsBeforeImplementation: true,
                autoGenerateTestTemplates: true,
            },
        };
    }
    async init() {
        const storageManager = this.configManager.getStorageManager();
        await storageManager.ensureStorageDirectories();
        const data = await storageManager.loadData(this.MODULE_NAME, this.DATA_FILE);
        if (data) {
            this.store = data;
        }
        else {
            // If file doesn't exist, create it with default store
            await this.save();
        }
    }
    async save() {
        const storageManager = this.configManager.getStorageManager();
        await storageManager.saveData(this.MODULE_NAME, this.DATA_FILE, this.store);
    }
    createFeature(name, description) {
        const feature = {
            id: this.generateId(),
            name,
            description,
            testCases: [],
            implementationStatus: 'not-started',
            testCoverage: 0,
            createdAt: new Date(),
            updatedAt: new Date(),
        };
        this.store.features[feature.id] = feature;
        return feature;
    }
    getFeature(nameOrId) {
        if (this.store.features[nameOrId]) {
            return this.store.features[nameOrId];
        }
        return Object.values(this.store.features).find(f => f.name === nameOrId);
    }
    addTestCase(featureNameOrId, testCase) {
        const feature = this.getFeature(featureNameOrId);
        if (!feature) {
            return null;
        }
        const newTest = {
            ...testCase,
            id: this.generateId(),
            createdAt: new Date(),
            updatedAt: new Date(),
        };
        feature.testCases.push(newTest);
        feature.updatedAt = new Date();
        this.updateTestCoverage(feature);
        return newTest;
    }
    updateTestStatus(featureNameOrId, testId, status) {
        const feature = this.getFeature(featureNameOrId);
        if (!feature) {
            return false;
        }
        const test = feature.testCases.find(t => t.id === testId);
        if (!test) {
            return false;
        }
        test.status = status;
        test.updatedAt = new Date();
        feature.updatedAt = new Date();
        this.updateTestCoverage(feature);
        return true;
    }
    getConfig() {
        return this.store.config;
    }
    updateConfig(updates) {
        Object.assign(this.store.config, updates);
    }
    updateTestCoverage(feature) {
        const totalTests = feature.testCases.length;
        const passingTests = feature.testCases.filter(t => t.status === 'passing').length;
        feature.testCoverage = totalTests > 0 ? (passingTests / totalTests) * 100 : 0;
    }
    generateTestTemplate(featureName, testName, language = 'typescript') {
        const templates = {
            typescript: `
describe('${featureName}', () => {
  it('${testName}', () => {
    // Arrange
    // TODO: Set up test data and dependencies
    
    // Act
    // TODO: Execute the code being tested
    
    // Assert
    // TODO: Verify the expected outcome
    expect(result).toBe(expected);
  });
});`,
            javascript: `
describe('${featureName}', () => {
  it('${testName}', () => {
    // Arrange
    // TODO: Set up test data and dependencies
    
    // Act
    // TODO: Execute the code being tested
    
    // Assert
    // TODO: Verify the expected outcome
    expect(result).toBe(expected);
  });
});`,
            python: `
import unittest

class Test${featureName.replace(/\s+/g, '')}(unittest.TestCase):
    def test_${testName.toLowerCase().replace(/\s+/g, '_')}(self):
        # Arrange
        # TODO: Set up test data and dependencies
        
        # Act
        # TODO: Execute the code being tested
        
        # Assert
        # TODO: Verify the expected outcome
        self.assertEqual(result, expected)`,
        };
        return templates[language] || templates.typescript;
    }
    generateId() {
        return Date.now().toString(36) + Math.random().toString(36).substr(2);
    }
}
//# sourceMappingURL=store.js.map