// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

/**
 * @title HDGLCommitment
 * @dev Minimal contract - just stores HDGL state commitments
 * No ZK proofs, no tokens - pure simplicity
 */
contract HDGLCommitment {
    
    // Simple commitment storage
    struct Commitment {
        bytes32 hash;
        uint256 timestamp;
        uint256 evolutionCount;
    }
    
    // State
    mapping(bytes32 => Commitment) public commitments;
    bytes32[] public commitmentHistory;
    bytes32 public latestCommitment;
    address public bridge;
    
    // Events
    event CommitmentSubmitted(bytes32 indexed commitment, uint256 evolutionCount);
    
    constructor(address _bridge) {
        bridge = _bridge;
    }
    
    /**
     * @notice Submit HDGL state commitment
     * @param commitment Keccak256 hash of 8 dimensions
     * @param evolutionCount Evolution counter from Solana
     */
    function submitCommitment(bytes32 commitment, uint256 evolutionCount) external {
        require(msg.sender == bridge, "Only bridge");
        require(commitment != bytes32(0), "Invalid commitment");
        
        commitments[commitment] = Commitment({
            hash: commitment,
            timestamp: block.timestamp,
            evolutionCount: evolutionCount
        });
        
        commitmentHistory.push(commitment);
        latestCommitment = commitment;
        
        emit CommitmentSubmitted(commitment, evolutionCount);
    }
    
    /**
     * @notice Get commitment by hash
     */
    function getCommitment(bytes32 hash) external view returns (
        bytes32 commitmentHash,
        uint256 timestamp,
        uint256 evolutionCount
    ) {
        Commitment memory c = commitments[hash];
        return (c.hash, c.timestamp, c.evolutionCount);
    }
    
    /**
     * @notice Check if commitment exists and is recent (< 1 hour old)
     */
    function isCommitmentValid(bytes32 hash) external view returns (bool) {
        Commitment memory c = commitments[hash];
        return c.hash != bytes32(0) && block.timestamp - c.timestamp < 1 hours;
    }
    
    /**
     * @notice Get total number of commitments
     */
    function getCommitmentCount() external view returns (uint256) {
        return commitmentHistory.length;
    }
    
    /**
     * @notice Update bridge address (admin function)
     */
    function setBridge(address _newBridge) external {
        require(msg.sender == bridge, "Only current bridge");
        bridge = _newBridge;
    }
}
