// This may look like C code, but it's really -*- C++ -*-
/*
 * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
 *
 * See the LICENSE file for terms of use.
 */

#ifndef WDATE_VALIDATOR_H_
#define WDATE_VALIDATOR_H_

#include <WDate>
#include <WValidator>

namespace Wt {

/*! \brief A validator for date strings.
 *
 * This validator accepts input in the given date format, and checks
 * if the the input was valid.
 */
class WDateValidator : public WValidator
{
public:
  /*! \brief Construct a date validator.
   *
   * The validator will accept only dates in the indicated range.
   * The format is by default 'yyyy-MM-dd'
   *
   * \sa WDate::fromString(const WString&, const WString&)
   */
  WDateValidator(const WDate& bottom = WDate(),
		 const WDate& top = WDate());

  /*! \brief Construct a date validator.
   *
   * The validator will accept only dates in the indicated range.
   * The format follows the syntax of
   * WDate::fromString(const WString&, const WString&)
   *
   * \sa WDate::fromString(const WString&, const WString&)
   */
  WDateValidator(const WString& format,
		 const WDate& bottom = WDate(),
		 const WDate& top = WDate());

  /*! \brief Set the message to display when the input is not a date.
   */
  void setInvalidNotADateText(const WString& text);

  /*! \brief Set the bottom of the valid date range.
   */
  void setBottom(const WDate& bottom);

  /*! \brief Get the bottom date of the valid range.
   */
  const WDate& bottom() const { return bottom_; }

  /*! \brief Set message to display when the date is earlier than bottom
   */
  void setInvalidTooEarlyText(const WString& text);

  /*! \brief Set the top of the valid date range.
   */
  void setTop(const WDate& top);

  /*! \brief Get the top date of the valid range.
   */
  const WDate& top() const { return top_; }

  /*! \brief Set message to display when the date later than top.
   */
  void setInvalidTooLateText(const WString& text);

  /*! \brief Set the date format used to parse date strings.
   *
   * \sa WDate::fromString(const WString&, const WString&)
   */
  void setFormat(const WString& format);

  /*! \brief Get the format string used to parse date strings
   *
   * \sa setFormat()
   */
  const WString& format() const { return format_; }

  virtual State validate(WString& input, int& pos) const;

  virtual void createExtConfig(std::ostream& config) const;

  /*! \brief Parse a date from a string.
   *
   * Equivalent to WDate::fromString(<i>input</i>, "yyyy-MM-dd");
   *
   * <i>Deprecated, see WDate::fromString() static methods</i>
   */
  static WDate parse(const WString& input);

private:
  WString format_;
  WDate   bottom_, top_;

  WString tooEarlyText_;
  WString tooLateText_;
  WString notADateText_;
};

}

#endif // DATE_VALIDATOR_H_
