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

// contract DisputeKitShutterTest {
//     struct VoteIDInfo {
//         address owner;
//         bytes32 identity;
//         bool used;
//     }

//     // Stores voting details
//     mapping(uint256 => VoteIDInfo) public voteIDRegistry;

//     // Tracks identity commitments
//     mapping(bytes32 identity => mapping(address juror => bool registered)) public registeredIdentities;

//     // Records actual votes cast
//     mapping(uint256 disputeID => mapping(uint256 voteID => uint256 vote)) public jurorVotes;

//     // Tracks used signatures to prevent replay attacks
//     mapping(bytes32 signature => bool used) public usedSignatures;

//     event VoteRevealed(
//         uint256 indexed disputeID,
//         address indexed juror,
//         uint256[] voteIDs,
//         uint256 vote,
//         bytes32 identity
//     );

//     function castVote(
//         uint256 _disputeID,
//         uint256[] calldata _voteIDs,
//         uint256 _vote,
//         bytes calldata signature
//     ) external {
//         require(_voteIDs.length > 0, "No vote IDs provided");

//         // 1. Signature Verification
//         bytes32 messageHash = keccak256(
//             abi.encodePacked(
//                 "\x19\x01",
//                 keccak256(
//                     abi.encode(
//                         keccak256("DisputeVote(uint256 disputeID,uint256[] voteIDs,uint256 vote)"),
//                         _disputeID,
//                         keccak256(abi.encodePacked(_voteIDs)),
//                         _vote
//                     )
//                 )
//             )
//         );

//         require(!usedSignatures[messageHash], "Signature already used");
//         usedSignatures[messageHash] = true;

//         address signer = _recoverSigner(messageHash, signature);

//         // TODO: add the identity to the input parameters?

//         // 2. Identity Validation
//         require(registeredIdentities[identity][signer], "Unregistered identity");

//         // 3. VoteID Ownership Check
//         for (uint i = 0; i < _voteIDs.length; i++) {
//             VoteIDInfo memory info = voteIDRegistry[_voteIDs[i]];

//             require(info.identity == identity, "Identity mismatch");
//             require(info.owner == signer, "VoteID owner mismatch");
//             require(!info.used, "VoteID already used");

//             voteIDRegistry[_voteIDs[i]].used = true;
//             jurorVotes[_disputeID][_voteIDs[i]] = _vote;
//         }

//         emit VoteRevealed(_disputeID, signer, _voteIDs, _vote, identity);
//     }

//     // Helper function to recover signer and identity hash
//     function _recoverSigner(bytes32 _messageHash, bytes memory _signature) internal pure returns (address) {
//         bytes32 r;
//         bytes32 s;
//         uint8 v;

//         assembly {
//             r := mload(add(_signature, 32))
//             s := mload(add(_signature, 64))
//             v := byte(0, mload(add(_signature, 96)))
//         }

//         require(uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, "Invalid signature");
//         require(v == 27 || v == 28, "Invalid signature version");

//         address signer = ecrecover(_messageHash, v, r, s);

//         return signer;
//     }
// }
