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

    uint256 public constant price = 30000000000000000; //0.03 ETH

    

    uint public constant maxPurchase = 20;

    uint256 public MAX;

    bool public saleIsActive = false;
    
    bool public phase1 = true;

    constructor(string memory name, string memory symbol, uint256 maxNftSupply) ERC721(name, symbol) {
        MAX = maxNftSupply;
    }

    function withdraw() public onlyOwner {
        uint balance = address(this).balance;
        address payable one = 0xC353062e0043aB93Fff0Ef4B86c58989C417166D;
        address payable two = 0xC1e5DF4E0762aAffb11012Eb4ADEb0D6AD1E7793;
        address payable three = 0xAB6201b7211829d58dB8CA15b121fb63B5040010;
        address payable four = 0x33d7622562A81ec65BC8bA138d11557B590633A5;
        address payable five = 0x7B6F6374bC98dA6b31d351B785c5A5760d66519e;
        address payable six = 0xb8dD2504A5D05adb777206f7e3AAC765bC493934;
        address payable seven = 0x56e11B783b3d90d58Eb921c7382Af50976DfD421;
        
        
        one.transfer(balance.mul(52000000000000000000).div(100000000000000000000));
        two.transfer(balance.mul(12500000000000000000).div(100000000000000000000));
        three.transfer(balance.mul(12500000000000000000).div(100000000000000000000));
        four.transfer(balance.mul(6000000000000000000).div(100000000000000000000));
        five.transfer(balance.mul(4000000000000000000).div(100000000000000000000));
        six.transfer(balance.mul(8000000000000000000).div(100000000000000000000));
        seven.transfer(balance.mul(5000000000000000000).div(100000000000000000000));

    }

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

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

 /*
    * Switch to Phase 2
    */
    function startPhaseTwo() public onlyOwner {
        phase1 = false;
    }
    
    
    /**
    * Mints Shuba
    */
    function mintShiba(uint numberOfTokens) public payable {
        require(saleIsActive, "Sale must be active to mint Shiba");
        require(numberOfTokens <= maxPurchase, "Can only mint 20 or less tokens at a time");
        require(price.mul(numberOfTokens) <= msg.value, "Ether value sent is not correct");
        
        if(phase1){
            require(totalSupply().add(numberOfTokens) <= 5000 , "Only 5000 in First Sale");
        }else{
            require(totalSupply().add(numberOfTokens) <= MAX, "Purchase would exceed max supply of Shiba");
        }
        
        
        for(uint i = 0; i < numberOfTokens; i++) {
            uint mintIndex = totalSupply();
            if (totalSupply() < MAX) {
                _safeMint(msg.sender, mintIndex);
            }
        }
    }
}
/**
 * @title SillyShiba Contract
 * @dev Extends ERC721 Non-Fungible Token Standard basic implementation
 */
function mintShiba(uint numberOfTokens) public payable {
    require(saleIsActive, "Sale must be active to mint Shiba");
    require(numberOfTokens <= maxPurchase, "Can only mint 20 or less tokens at a time");
    require(price.mul(numberOfTokens) <= msg.value, "Ether value sent is not correct");
        
    if(phase1){
        require(totalSupply().add(numberOfTokens) <= 5000 , "Only 5000 in First Sale");
    }else{
        require(totalSupply().add(numberOfTokens) <= MAX, "Purchase would exceed max supply of Shiba");
    }
        
        
    for(uint i = 0; i < numberOfTokens; i++) {
        uint mintIndex = totalSupply();
        if (totalSupply() < MAX) {
            _safeMint(msg.sender, mintIndex);
        }
    }
}

/**
 * Mints Shuba
 */