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

import {Test} from "forge-std/Test.sol";
import {AddressActivityRegistryV2} from "../../contracts/mainnet-checkpoint/AddressActivityRegistryV2.sol";

contract AddressActivityRegistryV2Test is Test {
    AddressActivityRegistryV2 registry;
    address admin = address(0xA11CE);

    event PaymentAttested(
        bytes32 indexed chain138TxHash,
        bytes32 indexed instructionId,
        address indexed creditor,
        address debtor,
        bytes32 uetr,
        uint64 batchId,
        uint8 msgTypeCode,
        uint256 valueWei,
        uint64 valueUsdE8,
        bytes32 payloadHash,
        bytes32 endToEndIdHash,
        bytes32 debtorRefHash,
        bytes32 creditorRefHash,
        bytes32 purposeHash,
        bytes32 receiptHash,
        uint256 blockNumber138
    );

    function setUp() public {
        registry = new AddressActivityRegistryV2(admin);
    }

    function testRecordBatchEmitsPaymentAttested() public {
        AddressActivityRegistryV2.IsoAttestationRecord[] memory rows =
            new AddressActivityRegistryV2.IsoAttestationRecord[](1);
        rows[0] = AddressActivityRegistryV2.IsoAttestationRecord({
            txHash: keccak256("tx1"),
            from: address(0x1),
            to: address(0x2),
            valueWei: 1 ether,
            blockNumber138: 1943065,
            blockTimestamp138: uint64(block.timestamp),
            valueUsdE8: 1_500_000_000_000_000,
            logCount: 1,
            receiptHash: keccak256("rcpt"),
            instructionId: keccak256("instr1"),
            endToEndIdHash: keccak256("e2e"),
            uetr: keccak256("uetr"),
            payloadHash: keccak256("payload"),
            msgTypeCode: registry.MSG_CHAIN138_SYNTH(),
            debtorRefHash: keccak256("d"),
            creditorRefHash: keccak256("c"),
            purposeHash: keccak256("p")
        });

        vm.prank(admin);
        vm.expectEmit(true, true, true, false);
        emit PaymentAttested(
            rows[0].txHash,
            rows[0].instructionId,
            rows[0].to,
            rows[0].from,
            rows[0].uetr,
            1,
            rows[0].msgTypeCode,
            rows[0].valueWei,
            rows[0].valueUsdE8,
            rows[0].payloadHash,
            rows[0].endToEndIdHash,
            rows[0].debtorRefHash,
            rows[0].creditorRefHash,
            rows[0].purposeHash,
            rows[0].receiptHash,
            rows[0].blockNumber138
        );
        registry.recordBatch(1, rows);
        assertTrue(registry.recorded(rows[0].txHash));
    }
}
