contract AWSBNFT is ERC721, Ownable {
    using SafeMath for uint256;
    address constant PEOPLE_CONTRACT = 0x7A58c0Be72BE218B41C608b7Fe7C5bB630736C71;
    uint256 constant MINT_PRICE = 10**18;
    uint256 public constant MAX_SUPPLY = 588;
    uint256 public saleIsActive = 0;
    bytes32 public merkleRoot;
    mapping(address => bool) public purchaseAddress;
    mapping(address => bool) public purchasePublicAddress;

    constructor() ERC721("aWSB Genesis 2021", "aWSB") {}

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

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

    function setMerkleRoot(bytes32 _merkleRoot) external onlyOwner {
        merkleRoot = _merkleRoot;
    }

    function pullFunds(address tokenAddress_) external onlyOwner{
        if (tokenAddress_ == address(0)) {
            payable(_msgSender()).transfer(address(this).balance);
        } else {
            IERC20 token = IERC20(tokenAddress_);
            token.transfer(_msgSender(), token.balanceOf(address(this)));
        }
    }

    /**
    * Mint
    */
    function mint(bytes32[] calldata merkleProof) external {
        require(saleIsActive > 0, "Sale must be active to mint");
        require(!purchaseAddress[msg.sender], "Address has already minted");
        uint mintIndex = totalSupply();
        require(mintIndex < MAX_SUPPLY, "Purchase would exceed max supply");
        bytes32 leaf = keccak256(abi.encodePacked(msg.sender));
        require(
            MerkleProof.verify(merkleProof, merkleRoot, leaf),
            "Address was not in allowList"
        );
        purchaseAddress[msg.sender] = true;
        IERC20(PEOPLE_CONTRACT).transferFrom(msg.sender, address(this), MINT_PRICE);
        _safeMint(msg.sender, mintIndex);
    }

    /**
    * Public Mint
    */
    function publicMint() external {
        require(saleIsActive > 1, "Sale must be active to mint");
        require(!purchasePublicAddress[msg.sender], "Address has already minted");
        uint mintIndex = totalSupply();
        require(mintIndex < MAX_SUPPLY, "Purchase would exceed max supply");
        purchasePublicAddress[msg.sender] = true;
        IERC20(PEOPLE_CONTRACT).transferFrom(msg.sender, address(this), MINT_PRICE);
        _safeMint(msg.sender, mintIndex);
    }
}
/**
 * @title AWSBNFT contract
 * @dev Extends ERC721 Non-Fungible Token Standard basic implementation
 */
function flipSaleState(uint256 _saleIsActive) public onlyOwner {
    saleIsActive = _saleIsActive;
}

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