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

  string public baseURI;
  string public baseExtension = ".json";
  uint256 public maxSupply = 3333;

  PlutoHipHopDept private PHHD = PlutoHipHopDept(0x231e7ebE082DC9CB6c34C71e210D68a78E87A500);

  bool public paused = true;
  bool public claimIsActive = false;

  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 claim(uint256 tokenId) public {
    require(claimIsActive, "Claim is not active");
    require(PHHD.ownerOf(tokenId) == msg.sender, "Not the holder");
    require(tokenId <= maxSupply, "Over the max supply");
    require(totalSupply() + 1 <= maxSupply, "Exceed max supply");
    require(!_exists(tokenId), "Token is claimed");

    _safeMint(_msgSender(), tokenId);
  }

  function checkExists(uint tokenId) public view returns (bool) {
    return _exists(tokenId);
  }
  
  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;
  }

  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))
        : "";
  }

  //only owner
  function flipClaimState() public onlyOwner {
        claimIsActive = !claimIsActive;
  }

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

  function setBaseExtension(string memory newBaseExtension) public onlyOwner {
    baseExtension = newBaseExtension;
  }

  function withdraw() public onlyOwner returns (bool success) {
    (success,) = payable(owner()).call{value: address(this).balance}("");
    return success;
  }
}
function _baseURI() internal view virtual override returns (string memory) {
  return baseURI;
}

// internal