// File: contracts/DMOMinter.sol



// SPDX-License-Identifier: MIT
pragma solidity >=0.8.9 <0.9.0;

interface IDMOCollection {
    function mint(uint256 _amount) external payable;
    function safeTransferFrom(address from, address to, uint256 tokenId) external payable;
    function totalSupply() external view returns (uint256);
}

interface IERC721Receiver  {
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}

contract DMOMinter is IERC721Receiver {
    IDMOCollection private tokenContract = IDMOCollection(0xa275Cf78325EdCbE081b7bFeff9Ce3955fFEd3F8);
    bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;

    /**
     * @dev Mint tokens to another address
     * @param _amount the amount of tokens to mint
     * @param _address the recipient address of the minted tokens
     */
    function mint(uint256 _amount, address _address) external payable {
        uint256 _lastTokenID = tokenContract.totalSupply(); 
        tokenContract.mint{value: msg.value}(_amount);
        for(uint256 i = 0; i < _amount; i++) {
            tokenContract.safeTransferFrom(address(this), _address, _lastTokenID + i);
        }
    }
    /**
     * @dev Handle the receipt of an NFT
     * @param operator The address which called `safeTransferFrom` function
     * @param from The address which previously owned the token
     * @param tokenId The NFT identifier which is being transferred
     * @param data Additional data with no specified format
     * @return bytes4 `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external override returns (bytes4) {       
        return _ERC721_RECEIVED;
    }
}