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

    uint256 public constant hyenaPrice = 45000000000000000; //0.045 ETH

    uint public constant maxHyenaPurchase = 30;
    
    uint public totalSaleToken;
    
    uint public totalGiftToken;

    uint public TOTAL_GIFT;

    uint256 public MAX_HYENAS;

    bool public saleIsActive = false;

    constructor(string memory name, string memory symbol, uint256 maxNftSupply, uint totalGift) ERC721(name, symbol) {
        MAX_HYENAS = maxNftSupply;
        TOTAL_GIFT = totalGift;
    }

    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;
    }

    /**
    * Mints Kookie Hyenas
    */
    function mintHyena(uint numberOfTokens) public payable {
        require(saleIsActive, "Sale must be active to mint Hyena");
        require(numberOfTokens <= maxHyenaPurchase, "Can only mint 30 tokens at a time");
        require(totalSupply().sub(totalGiftToken).add(numberOfTokens) <= MAX_HYENAS.sub(TOTAL_GIFT), "Purchase would exceed max supply of Hyenas");
        require(hyenaPrice.mul(numberOfTokens) <= msg.value, "Ether value sent is not correct");
        
        for(uint i = 0; i < numberOfTokens; i++) {
            _safeMint(msg.sender, totalSaleToken + TOTAL_GIFT);
            totalSaleToken = totalSaleToken + 1;
        }
    }
    
    function giftHyena(address receiver, uint numberOfTokens) public onlyOwner {
        require(totalGiftToken + numberOfTokens <= TOTAL_GIFT, "Gift would exceed max supply of Hyenas");
        
        for(uint i = 0; i < numberOfTokens; i++) {
            _safeMint(receiver, totalGiftToken);
            totalGiftToken = totalGiftToken + 1;
        }
    }
}
/**
 * @title KookyHyena contract
 * @dev Extends ERC721 Non-Fungible Token Standard basic implementation
 */
function flipSaleState() public onlyOwner {
    saleIsActive = !saleIsActive;
}

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