#ifndef FIELD_H
#define FIELD_H
#include "expression.h"
#include "fieldproperties.h"

#include <QExplicitlySharedDataPointer>

class Table;
class Field : public Expression
{
private:

    QExplicitlySharedDataPointer<FieldProperties> m_properties;

public:
    Field(const BaseAdaptor * const db = 0,
          const QString &fieldName = QString(),
          QVariant::Type type = QVariant::String );

    friend bool operator==( const Field &left, const Field &right);
    friend bool operator<( const Field &left, const Field &right );

    virtual QString toString() const;

    Expression year() const;
    Expression month() const;
    Expression day() const;
    Expression hour() const;
    Expression minutes() const;
    Expression seconds() const;

    Expression avg() const;
    Expression first() const;
    Expression last() const;
    Expression count() const;
    Expression sum() const;
    Expression max() const;
    Expression min() const;

    Expression len() const;
    Expression lower() const;
    Expression upper() const;
    Expression mid() const;
    Expression round() const;

    Expression between( const QVariant &value1, const QVariant &value2 ) const;

    void setTable( const Table *parent );
    const Table *table() const;
    QString tableName() const;
    QString name() const;
    QString fullyQualifiedName() const;
    QString scopedName() const;
    QVariant::Type type() const;

    void setCheck( const Query &query );
    Query check() const;
    void setUnique( bool unique );
    void setNotNull( bool notnull );
    bool isUnique() const;
    bool isPrimaryKey() const;

    QVariant property( const QString &propname ) const;
    void setProperty( const QString &propname, const QVariant &value );
    void removeProperty( const QString &propname );

    virtual QString create( ) const;
    QString formattedName() const;
    QString formattedTableName() const;

};
bool operator==( const Field &left, const Field &right);
bool operator<( const Field &left, const Field &right );
Q_DECLARE_METATYPE(Field)
#endif // FIELD_H

