/*
 * Copyright (C) 2019-2021 Dmitriy Purgin <dmitriy.purgin@sequality.at>
 * Copyright (C) 2019-2021 sequality software engineering e.U. <office@sequality.at>
 *
 * This file is part of QtOrm library.
 *
 * QtOrm is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * QtOrm is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with QtOrm.  If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef QORMPROPERTYMAPPING_H
#define QORMPROPERTYMAPPING_H

#include <QtOrm/qormglobal.h>

#include <QtCore/qmetaobject.h>
#include <QtCore/qshareddata.h>
#include <QtCore/qstring.h>
#include <QtCore/qvariant.h>

QT_BEGIN_NAMESPACE

class QOrmMetadata;
class QOrmPropertyMappingPrivate;

class Q_ORM_EXPORT QOrmPropertyMapping
{
public:
    QOrmPropertyMapping(const QOrmMetadata& enclosingEntity,
                        QMetaProperty qMetaProperty,
                        QString classPropertyName,
                        QString tableFieldName,
                        bool isObjectId,
                        bool isAutoGenerated,
                        QMetaType::Type dataType,
                        const QOrmMetadata* referencedEntity,
                        bool isTransient,
                        bool isNotNull,
                        bool hasForeignKey,
                        bool isUnique,
                        QString uniqueGroup,
                        QOrmUserMetadata userMetadata);
    QOrmPropertyMapping(const QOrmPropertyMapping&);
    QOrmPropertyMapping(QOrmPropertyMapping&&);
    ~QOrmPropertyMapping();

    QOrmPropertyMapping& operator=(const QOrmPropertyMapping&);
    QOrmPropertyMapping& operator=(QOrmPropertyMapping&&);

    [[nodiscard]] const QOrmMetadata& enclosingEntity() const;
    [[nodiscard]] const QMetaProperty& qMetaProperty() const;
    [[nodiscard]] QString classPropertyName() const;
    [[nodiscard]] QString tableFieldName() const;
    [[nodiscard]] bool isObjectId() const;
    [[nodiscard]] bool isAutogenerated() const;
    [[nodiscard]] QMetaType::Type dataType() const;
    [[nodiscard]] QString dataTypeName() const;
    [[nodiscard]] bool isReference() const;
    [[nodiscard]] const QOrmMetadata* referencedEntity() const;
    [[nodiscard]] bool isTransient() const;
    [[nodiscard]] bool isNotNull() const;
    [[nodiscard]] bool hasForeignKey() const;
    [[nodiscard]] bool isUnique() const;
    [[nodiscard]] QString uniqueGroup() const;
    [[nodiscard]] const QOrmUserMetadata& userMetadata() const;

private:
    QSharedDataPointer<QOrmPropertyMappingPrivate> d;
};

extern Q_ORM_EXPORT QDebug operator<<(QDebug dbg, const QOrmPropertyMapping& propertyMapping);

QT_END_NAMESPACE

#endif
