contract Ashlings is ERC721A, Ownable {

  using Strings for uint256;

  string public baseURI;
  string public baseExtension = ".json";
  uint256 public cost = 4000000000000000000;
  uint256 public maxSupply = 5000;
  bool public paused = false;
  address public ashContract = 0x64D91f12Ece7362F91A6f8E7940Cd55F05060b92;


  constructor() ERC721A("Ashlings", "ASH") {
  }

  function mint(uint256 quantity) external {
    if (msg.sender != owner()) {
    require(!paused);   
    require(IERC20(ashContract).balanceOf(msg.sender) >= cost * quantity);
    IERC20(ashContract).transferFrom(msg.sender, address(this), cost * quantity);
    } 
    uint256 supply = totalSupply();
    require(quantity > 0);
    require(supply + quantity <= maxSupply);
    _safeMint(msg.sender, quantity);
  }


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


  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 setCost(uint256 _newCost) public onlyOwner {
    cost = _newCost;
  }

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

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

  function pause(bool _state) public onlyOwner {
    paused = _state;
  }
 

  function withdraw(uint256 _amount) public payable onlyOwner {
    require(payable(msg.sender).send(address(this).balance));
    IERC20(ashContract).transfer(msg.sender, _amount);
  }
}
function _baseURI() internal view virtual override returns (string memory) {
  return baseURI;
}

// internal