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

contract AgreementRegistry {
    struct Agreement {
        bytes32 agreementHash;
        string featureType;
        string summary;
        uint256 timestamp;
        address registeredBy;
    }

    mapping(string => Agreement) public agreements;  // negotiationId => Agreement
    string[] public agreementIds;

    event AgreementRegistered(
        string indexed negotiationId,
        bytes32 agreementHash,
        string featureType,
        string summary,
        uint256 timestamp
    );

    function registerAgreement(
        string calldata negotiationId,
        bytes32 agreementHash,
        string calldata featureType,
        string calldata summary
    ) external {
        agreements[negotiationId] = Agreement({
            agreementHash: agreementHash,
            featureType: featureType,
            summary: summary,
            timestamp: block.timestamp,
            registeredBy: msg.sender
        });
        agreementIds.push(negotiationId);

        emit AgreementRegistered(
            negotiationId, agreementHash, featureType, summary, block.timestamp
        );
    }

    function getAgreement(string calldata negotiationId)
        external view returns (Agreement memory)
    {
        return agreements[negotiationId];
    }

    function totalAgreements() external view returns (uint256) {
        return agreementIds.length;
    }
}
