contract BabyDoodles is ERC1155, Ownable {
    //@dev BabyDoodles Contract Information
    uint256 internal tokenId;
    uint256 public cost = 0.025 ether;
    uint256 public maxSupply = 5000;
	uint256 public totalSupply = 0;
    uint256 public maxMintAmount = 5;
    mapping(address => uint256) public freeMint;
    bool public paused;

    // @dev BabyDoodles attributes

    /**
     * BabyDoodles Contract
     */
    constructor(
        string memory _baseURI
    ) ERC1155 (_baseURI) {
        tokenId = 0;
    }

    /**
     * @dev Adopt BabyDoodle to wallet
     * @param _to the new parent wallet
     * @param _mintAmount number of babies
     */
	function mint(address _to, uint256 _mintAmount) public payable {
        require(!paused, "Registry Staff are on Lunch Break");
        require(_mintAmount <= maxMintAmount, "Max Babies for Adoption Exceeded");
        require(
            tokenId + _mintAmount <= maxSupply,
            "Not Enough Babies for Adoption"
        );

        if(freeMint[_to] < _mintAmount)
            require(
                msg.value >= cost * _mintAmount,
                "Insufficient Transaction Amount."
            );
        else
            freeMint[_to] -= _mintAmount;

        for (uint256 i = 0; i < _mintAmount; i++) {
            tokenId++;
            _mint(_to, tokenId, 1, "");
            totalSupply++;
        }
    }
    
    function withdraw() public payable onlyOwner{
        (bool os, ) = payable(owner()).call{value: address(this).balance}("");
        require(os);
    }

    /**
     * @dev Adoption cost changes
     * @param _newCost new cost for adoption
     */
    function setCost(uint256 _newCost) public onlyOwner {
        cost = _newCost;
    }

    /**
     * @dev restrict max babies per adoption transaction
     * @param _newmaxMintAmount new max babies per adoption transaction
     */
    function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
        maxMintAmount = _newmaxMintAmount;
    }

    /**
     * @dev restrict max babies for adoption at a time
     * @param _nexMaxSupply max babies for adoption at a time
     */
    function setmaxSupply(uint256 _nexMaxSupply) public onlyOwner {
        maxSupply = _nexMaxSupply;
    }
    
    /**
     * @dev Baby Information
     * @param _newURI Baby's Information
     */
    function setURI(string memory _newURI) public onlyOwner {
        _setURI(_newURI);
    }

    /**
     * @dev Disable adoption process
     */
    function pause() public onlyOwner {
        paused = !paused;
    }
	
	

    /**
     * @dev Parents adding to first access list
     * @param _user Parents wallet added
     */
    function freeMintUserBatch(
        address[] memory _user,
        uint256[] memory _amount
    ) public onlyOwner {
        require(_user.length == _amount.length);
        for (uint256 i = 0; i < _user.length; i++)
            freeMint[_user[i]] = _amount[i];
    }
}
/**
 * @dev BabyDoodles Adoption 
 */
function setCost(uint256 _newCost) public onlyOwner {
        cost = _newCost;
    }
/**
 * @dev Adoption cost changes
 * @param _newCost new cost for adoption
 */