contract NFTArtGen is ERC721, Ownable {
    string internal baseUri;

    uint256 public cost = 0.05 ether;
    uint32 public maxPerMint = 5;
    uint32 public maxPerWallet = 20;
    uint32 public supply = 0;
    uint32 public totalSupply = 0;
    bool public open = false;
    mapping(address => uint256) internal addressMintedMap;

    uint32 private commission = 49; // 4.9%
    address private author = 0x460Fd5059E7301680fA53E63bbBF7272E643e89C;

    constructor(
        string memory _uri,
        string memory _name,
        string memory _symbol,
        uint32 _totalSupply,
        uint256 _cost,
        bool _open
    ) ERC721(_name, _symbol) {
        baseUri = _uri;
        totalSupply = _totalSupply;
        cost = _cost;
        open = _open;
    }

    // ------ Author Only ------

    function setCommission(uint32 _commision) public {
        require(msg.sender == author, "Incorrect Address");
        commission = _commision;
    }

    // ------ Owner Only ------

    function setCost(uint256 _cost) public onlyOwner {
        cost = _cost;
    }

    function setOpen(bool _open) public onlyOwner {
        open = _open;
    }

    function setMaxPerWallet(uint32 _max) public onlyOwner {
        maxPerWallet = _max;
    }

    function setMaxPerMint(uint32 _max) public onlyOwner {
        maxPerMint = _max;
    }

    function airdrop(address[] calldata to) public onlyOwner {
        for (uint32 i = 0; i < to.length; i++) {
            require(1 + supply <= totalSupply, "Limit reached");
            _safeMint(to[i], ++supply, "");
        }
    }

    function withdraw() public payable onlyOwner {
        (bool success, ) = payable(msg.sender).call{
            value: address(this).balance
        }("");
        require(success);
    }

    // ------ Mint! ------

    function mint(uint32 count) external payable preMintChecks(count) {
        require(open == true, "Mint not open");
        performMint(count);
    }

    function performMint(uint32 count) internal {
        for (uint32 i = 0; i < count; i++) {
            _safeMint(msg.sender, ++supply, "");
        }
        
        addressMintedMap[msg.sender] += count;

        (bool success, ) = payable(author).call{
            value: (msg.value * commission) / 1000
        }("");
        require(success);
    }

    // ------ Read ------

    // ------ Modifiers ------

    modifier preMintChecks(uint32 count) {
        require(count > 0, "Mint at least one.");
        require(count < maxPerMint + 1, "Max mint reached.");
        require(msg.value >= cost * count, "Not enough fund.");
        require(supply + count < totalSupply + 1, "Mint sold out");
        require(
            addressMintedMap[msg.sender] + count <= maxPerWallet,
            "Max total mint reached"
        );
        _;
    }
}
// 
// Built by https://nft-generator.art
// 
function setCost(uint256 _cost) public onlyOwner {
    cost = _cost;
}

// ------ Owner Only ------