contract AlistApes is ERC721, Ownable {
    using SafeMath for uint256;




    uint256 public  alistPrice = 0.08 ether; //0.08 ETH

    uint public  maxAlistMintPerTxn = 20;
    
    address public companyWallet1;
    address public companyWallet2;

    uint256 public MAX_ALIST = 10000;

    bool public saleIsActive = false;

    uint256 public totalCompanyClaimed;


    constructor(address _companyWallet1,address _companyWallet2) ERC721("A List Apes", "ALIST") {
        companyWallet1 = _companyWallet1;
        companyWallet2 = _companyWallet2;

    
    }



    function claimCompanyReserve(uint256 noOfItems) public onlyOwner{
        require(noOfItems.add(totalCompanyClaimed) <=200,"Max Claim for Company Exceeds");
        for(uint256 i=0;i< noOfItems;i++){
            uint mintIndex = totalSupply();
            _mint(msg.sender,mintIndex);
        }
    }


    function setPrice(uint256 _price)public onlyOwner{
        alistPrice = _price;
    }

    function withdraw() public onlyOwner {
        uint balance = address(this).balance;
        msg.sender.transfer(balance);
    }


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

    /*
    * Pause sale if active, make active if paused
    */
    function flipSaleState() public onlyOwner {
        saleIsActive = !saleIsActive;
    }


    function setMaxAlistMintPerTxn(uint num) public onlyOwner {
        maxAlistMintPerTxn = num;
    }

  
    function mint(uint numberOfTokens) public payable {
        require(saleIsActive, "Sale must be active to mint alist");
        require(numberOfTokens <= maxAlistMintPerTxn, "Can only mint 20 tokens at a time");
        require(totalSupply().add(numberOfTokens) <= MAX_ALIST, "Purchase would exceed max supply of ALIST");
        require(alistPrice.mul(numberOfTokens) <= msg.value, "Ether value sent is not correct");
        for(uint i = 0; i < numberOfTokens; i++) {
           _mintAList(msg.sender);
        }
        
        uint256 halfBal = address(this).balance.div(2);

        payable(companyWallet1).transfer(halfBal);
        payable(companyWallet2).transfer(halfBal);


    }

    function _mintAList(address to) internal {
         uint mintIndex = totalSupply();
        _safeMint(to, mintIndex);
    }
    

    
}
function flipSaleState() public onlyOwner {
    saleIsActive = !saleIsActive;
}

/*
 * Pause sale if active, make active if paused
 */