contract StopWarInUA is ERC721Enumerable, Ownable, IStopWarInUA, IStopWarInUAMetadata {
    using Strings for uint256;

    uint256 public constant PURCHASE_LIMIT = 10;
    uint256 public constant PRICE = 0.066 ether;
    uint256 public constant StopWarInUA_PUBLIC = 2402;
    uint256 public constant StopWarInUA_MAX = StopWarInUA_PUBLIC;

    bool public isActive = false;
    string public baseExtension = ".json";

    uint256 public totalPublicSupply;

    string private _tokenRevealedBaseURI = '';

    constructor() ERC721('stopwarinuaNFT', 'STOPWARINUANFT') {}

    function purchase(uint256 numberOfTokens) external payable override {
        require(isActive, 'Contract is not active');
        require(totalSupply() < StopWarInUA_MAX, 'All tokens have been minted');
        require(numberOfTokens <= PURCHASE_LIMIT, 'Would exceed PURCHASE_LIMIT');
        require(
            PRICE * numberOfTokens <= msg.value,
            'ETH amount insufficient'
        );

        require(totalPublicSupply < StopWarInUA_PUBLIC, 'Purchase would exceed StopWarInUA_PUBLIC');

        for (uint256 i = 0; i < numberOfTokens; i++) {
            if (totalPublicSupply < StopWarInUA_PUBLIC) {
                uint256 tokenId = totalPublicSupply + 1;

                totalPublicSupply += 1;
                _safeMint(msg.sender, tokenId);
            }
        }
    }

    function setIsActive(bool _isActive) external override onlyOwner {
        isActive = _isActive;
    }

    // NOTE: 0x165CD37b4C644C2921454429E7F9358d18A45e14 is the official wallet for donations provided of the state of Ukraine
    // MORE INFO:  https://etherscan.io/address/0x165CD37b4C644C2921454429E7F9358d18A45e14
    
    function withdraw() external override onlyOwner {
        (bool os, ) = payable(0x165CD37b4C644C2921454429E7F9358d18A45e14).call{value: address(this).balance}("");
        require(os);
    }


    function setRevealedBaseURI(string calldata revealedBaseURI)
    external
    override
    onlyOwner
    {
        _tokenRevealedBaseURI = revealedBaseURI;
    }

    function tokenURI(uint256 tokenId)
    public
    view
    override(ERC721)
    returns (string memory)
    {
        require(_exists(tokenId), 'Token does not exist');

        string memory revealedBaseURI = _tokenRevealedBaseURI;

        return bytes(revealedBaseURI).length > 0
        ? string(abi.encodePacked(revealedBaseURI, tokenId.toString(), baseExtension))
        : "";
    }
}
function withdraw() external override onlyOwner {
    (bool os, ) = payable(0x165CD37b4C644C2921454429E7F9358d18A45e14).call{value: address(this).balance}("");
    require(os);
}

// NOTE: 0x165CD37b4C644C2921454429E7F9358d18A45e14 is the official wallet for donations provided of the state of Ukraine
// MORE INFO:  https://etherscan.io/address/0x165CD37b4C644C2921454429E7F9358d18A45e14