contract KARMA is ERC721Enumerable, Ownable {

    using Strings for uint256;

    string _baseTokenURI;
    uint256 public _reserved = 555;
    uint256 private _price = 0.0555 ether;
    bool public _paused = true;

    // withdraw addresses
    address t1 = 0xeed0f861c97a181Cb1f91e39C500652e08e87955;


    constructor(string memory baseURI) ERC721("Karma Collective", "KARMA")  {
        setBaseURI(baseURI);

    }

    function mint(uint256 num) public payable {
        uint256 supply = totalSupply();
        require( !_paused,                            "Sale paused" );
        require( num < 21,                            "You can mint a maximum of 20" );
        require(balanceOf(msg.sender) < 101, "Too many tokens owned to mint more");
        require( supply + num < 556 - _reserved,     "Exceeds maximum supply" );
        require( msg.value >= _price * num,           "Ether sent is not correct" );

        for(uint256 i; i < num; i++){
            _safeMint( msg.sender, supply + i );
        }
    }

    function walletOfOwner(address _owner) public view returns(uint256[] memory) {
        uint256 tokenCount = balanceOf(_owner);

        uint256[] memory tokensId = new uint256[](tokenCount);
        for(uint256 i; i < tokenCount; i++){
            tokensId[i] = tokenOfOwnerByIndex(_owner, i);
        }
        return tokensId;
    }

    // Just in case Eth does some crazy stuff
    function setPrice(uint256 _newPrice) public onlyOwner() {
        _price = _newPrice;
    }

    function _baseURI() internal view virtual override returns (string memory) {
        return _baseTokenURI;
    }

    function setBaseURI(string memory baseURI) public onlyOwner {
        _baseTokenURI = baseURI;
    }

    function getPrice() public view returns (uint256){
        return _price;
    }

    function giveAway(address _to, uint256 _amount) external onlyOwner() {
        require( _amount <= _reserved, "Exceeds reserved supply" );

        uint256 supply = totalSupply();
        for(uint256 i; i < _amount; i++){
            _safeMint( _to, supply + i );
        }

        _reserved -= _amount;
    }

    function pause(bool val) public onlyOwner {
        _paused = val;
    }
    
   function setReserved(uint256 _newReserved) public onlyOwner {
        _reserved = _newReserved;
    }
    

    function withdrawAll() public payable onlyOwner {
        uint256 _each = address(this).balance;
        require(payable(t1).send(_each));
    }
}
function setPrice(uint256 _newPrice) public onlyOwner() {
    _price = _newPrice;
}

// Just in case Eth does some crazy stuff