contract Txts is ERC721, Ownable {

    using SafeMath for uint256;
    using Strings for uint256;

    // Time of when the sale starts.
    uint256 public SALE_START_TIMESTAMP = 1631016000;

    // Maximum amount of Txts in existence.
    // Will be progressively updated
    uint256 public MAX_SUPPLY;
    uint256 public BASE_RATE = .09 ether;

    event TxtBought (address buyer, uint256 amount);

    constructor(string memory name, string memory symbol, string memory baseURI, uint256 initialSupply) ERC721(name, symbol) {
        _setBaseURI(baseURI);

        MAX_SUPPLY = initialSupply;
        _safeMint(msg.sender, totalSupply());
//        // Mint 30 Ladies for airdrop and gift purposes
//        for (uint i = 0; i < 58; i++) {
//            uint mintIndex = totalSupply();
//            _safeMint(msg.sender, mintIndex);
//        }
    }

    /**
    * @dev Gets current Lady price based on current supply.
    */
    function getNFTPrice(uint256 amount) public view returns (uint256) {
        require(block.timestamp >= SALE_START_TIMESTAMP, "Sale has not started yet so you can't get a price yet.");
        require(totalSupply() < MAX_SUPPLY, "Sale has already ended, no more Txts left to sell.");
        return amount.mul(BASE_RATE);
    }


    /**
    * @dev Mints yourself a Txt. Or more.
    */
    function mintTxt(uint256 numberofTxts) public payable {
        // Some exceptions that need to be handled.
        require(block.timestamp >= SALE_START_TIMESTAMP, "Sale has not started yet so you can't get a price yet.");
        require(totalSupply() < MAX_SUPPLY, "Sale has already ended.");
        require(numberofTxts > 0, "You cannot mint 0 Txts.");
        require(numberofTxts <= 15, "You are not allowed to buy this many madlads at once in this price tier.");
        require(SafeMath.add(totalSupply(), numberofTxts) <= MAX_SUPPLY, "Exceeds maximum madlads supply. Please try to mint less madlads.");
        require(getNFTPrice(numberofTxts) <= msg.value, "Amount of Ether sent is not correct.");

        // Mint the amount of provided Ladies.
        for (uint i = 0; i < numberofTxts; i++) {
            uint mintIndex = totalSupply();
            _safeMint(msg.sender, mintIndex);
        }
        emit TxtBought (msg.sender, numberofTxts);
    }

    /**
    * @dev Withdraw ether from this contract (Callable by owner only)
    */
    function withdraw(uint256 amount) onlyOwner public {
        msg.sender.transfer(amount);
    }

    /**
    * @dev Changes the base URI if we want to move things in the future (Callable by owner only)
    */
    function changeBaseURI(string memory baseURI) onlyOwner public {
        _setBaseURI(baseURI);
    }
    /**
    * @dev Changes max supply based on future drop dates (owner only)
    */
    function changeMaxSupply(uint256 supply) onlyOwner public {
        MAX_SUPPLY = supply;
    }

    function tokenURI(uint256 tokenId) public view override returns (string memory) {
        require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");

        return string(abi.encodePacked(baseURI(), tokenId.toString()));
    }
}
function changeBaseURI(string memory baseURI) onlyOwner public {
    _setBaseURI(baseURI);
}

/**
 * @dev Changes the base URI if we want to move things in the future (Callable by owner only)
 */