contract PictureDayLimited is ERC721Enumerable, Ownable {
    using Strings for uint256;

    // Variables
    string baseURI;
    string public baseExtension = ".json"; // Base extension of metadata file
    uint256 public cost = 0.001 ether; // Cost of each NFT
    uint256 public maxSupply = 28; // Max amount of NFTs that can be minted in total
    uint256 public maxMintAmount = 3; // Max amount to be minted at once
    bool public paused = false; // Contract paused when deployed

    // Constructor
    constructor(
        string memory _name,
        string memory _symbol,
        string memory _initBaseURI
    ) ERC721(_name, _symbol) {
        setBaseURI(_initBaseURI);
    }

    // Internal
    function _baseURI() internal view virtual override returns (string memory) {
        return baseURI;
    }

    function contractURI() public pure returns (string memory) {
        return "https://gateway.pinata.cloud/ipfs/QmPsenT9dfK9xEEAuHA3pCWQVKJEBmceZazJcttdtJeoBX/data.json";
    }

    // Public
    // Minting to owner's wallet
    function mint(uint256 _mintAmount) public payable {
        uint256 supply = totalSupply();
        require(!paused, "contract is paused.");
        require(_mintAmount > 0, "need to mint at least 1 NFT");
        require(_mintAmount <= maxMintAmount, "max mint amount per session exceeded");
        require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");

        if (msg.sender != owner()) {
            require(msg.value >= cost * _mintAmount, "insufficient balance");
        }

        for (uint256 i = 1; i <= _mintAmount; i++) {
            _safeMint(msg.sender, supply + i);
        }
    }

    // Minting to a specific wallet address
    function mintFor(address to, uint256 _mintAmount) public payable {
        uint256 supply = totalSupply();
        require(!paused, "contract is paused.");
        require(_mintAmount > 0, "need to mint at least 1 NFT");
        require(_mintAmount <= maxMintAmount, "max mint amount per session exceeded");
        require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");

        if (msg.sender != owner()) {
            require(msg.value >= cost * _mintAmount, "insufficient balance");
        }

        for (uint256 i = 1; i <= _mintAmount; i++) {
            _safeMint(to, supply + i);
        }
    }

    // Returns token Ids for a specific wallet
    function walletOfOwner(address _owner)
        public
        view
        returns (uint256[] memory)
    {
        uint256 ownerTokenCount = balanceOf(_owner);
        uint256[] memory tokenIds = new uint256[](ownerTokenCount);
        for (uint256 i; i < ownerTokenCount; i++) {
            tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
        }
        return tokenIds;
    }

    // Returns token URI against a specific token ID
    function tokenURI(uint256 tokenId)
        public
        view
        virtual
        override
        returns (string memory)
    {
        require(
            _exists(tokenId),
            "ERC721Metadata: URI query for nonexistent token"
        );

        string memory currentBaseURI = _baseURI();
        return
            bytes(currentBaseURI).length > 0
                ? string(
                    abi.encodePacked(
                        currentBaseURI,
                        tokenId.toString(),
                        baseExtension
                    )
                )
                : "";
    }

    // Update NFT price
    function setCost(uint256 _newCost) public onlyOwner {
        cost = _newCost;
    }

    // Update maximum amount of NFTs that can be minted at once.
    function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
        maxMintAmount = _newmaxMintAmount;
    }

    // Update original image URI
    function setBaseURI(string memory _newBaseURI) public onlyOwner {
        baseURI = _newBaseURI;
    }

    // Update extension for metadata file
    function setBaseExtension(string memory _newBaseExtension)
        public
        onlyOwner
    {
        baseExtension = _newBaseExtension;
    }

    // Pause smart contract to stop minting
    function pause(bool _state) public onlyOwner {
        paused = _state;
    }

    // Withdraw funds from NFT contract
    function withdraw() public payable onlyOwner {
        // Withdraw remaining to Smart Contract Owner's wallet
        (bool os, ) = payable(owner()).call{value: address(this).balance}("");
        require(os);
    }
}
// Smart Contract -- Coded By ShAj
function mint(uint256 _mintAmount) public payable {
        uint256 supply = totalSupply();
        require(!paused, "contract is paused.");
        require(_mintAmount > 0, "need to mint at least 1 NFT");
        require(_mintAmount <= maxMintAmount, "max mint amount per session exceeded");
        require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");

        if (msg.sender != owner()) {
            require(msg.value >= cost * _mintAmount, "insufficient balance");
        }

        for (uint256 i = 1; i <= _mintAmount; i++) {
            _safeMint(msg.sender, supply + i);
        }
    }
// Public
// Minting to owner's wallet