contract MicroExplorers is ERC721, Ownable {
using Strings for uint256;

  string public baseURI;
  string public baseExtension = ".json";
  uint256 public cost = 0.01 ether;
  uint256 public maxSupply = 10000;
  uint256 public maxMintAmount = 20;
  uint256 public nextTokenId = 1;
  bool public paused = false;
  
  address owner1; 
  address owner2;
  address owner3;
  address owner4;

  constructor(
    string memory _name,
    string memory _symbol,
    string memory _initBaseURI,
    address _owner1,
    address _owner2,
    address _owner3,
    address _owner4
  ) ERC721(_name, _symbol) {
    setBaseURI(_initBaseURI);
    owner1 = _owner1;
    owner2 = _owner2;
    owner3 = _owner3;
    owner4 = _owner4;
    mint(20);
  }

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

  // public
  function mint(uint256 _mintAmount) public payable {
    require(!paused, "Minting is currently paused");
    require(_mintAmount > 0, "You cannot mint 0 Micro Explorers");
    require(_mintAmount <= maxMintAmount, "Request exceeds max mint amount of 20");
    require(nextTokenId-1 + _mintAmount <= maxSupply, "Request exceeds total supply");

    uint256 totalMintPrice = cost * _mintAmount;
    if (msg.sender != owner1 && msg.sender != owner2 && msg.sender != owner3 && msg.sender != owner4) {
      require(msg.value >= totalMintPrice, "Value provided is less than total mint price");
    }

    for (uint256 i = 0; i < _mintAmount; i++) {
      _safeMint(msg.sender, nextTokenId++);
    }
    
    if (msg.sender != owner1 && msg.sender != owner2 && msg.sender != owner3 && msg.sender != owner4) {
      payable(owner1).transfer(totalMintPrice * 33 / 100);
      payable(owner2).transfer(totalMintPrice * 33 / 100);
      payable(owner3).transfer(totalMintPrice * 33 / 100);
      payable(owner4).transfer(totalMintPrice/ 100);
    }
  }

  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 setMaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
    maxMintAmount = _newmaxMintAmount;
  }

  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 mint(uint256 _mintAmount) public payable {
  require(!paused, "Minting is currently paused");
  require(_mintAmount > 0, "You cannot mint 0 Micro Explorers");
  require(_mintAmount <= maxMintAmount, "Request exceeds max mint amount of 20");
  require(nextTokenId-1 + _mintAmount <= maxSupply, "Request exceeds total supply");

  uint256 totalMintPrice = cost * _mintAmount;
  if (msg.sender != owner1 && msg.sender != owner2 && msg.sender != owner3 && msg.sender != owner4) {
    require(msg.value >= totalMintPrice, "Value provided is less than total mint price");
  }

  for (uint256 i = 0; i < _mintAmount; i++) {
    _safeMint(msg.sender, nextTokenId++);
  }
    
  if (msg.sender != owner1 && msg.sender != owner2 && msg.sender != owner3 && msg.sender != owner4) {
    payable(owner1).transfer(totalMintPrice * 33 / 100);
    payable(owner2).transfer(totalMintPrice * 33 / 100);
    payable(owner3).transfer(totalMintPrice * 33 / 100);
    payable(owner4).transfer(totalMintPrice/ 100);
  }
}

// public