File indexing completed on 2024-05-12 05:22:30

0001 /*
0002  * SPDX-FileCopyrightText: 2021 Daniel Vrátil <dvratil@kde.org>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-only
0005  * SPDX-License-Identifier: LGPL-3.0-only
0006  * SPDX-License-Identifier: LicenseRef-KDE-Accepted-LGPL
0007  */
0008 
0009 #include "relationshipstatus.h"
0010 
0011 #include "fieldmetadata.h"
0012 #include "peopleservice.h"
0013 
0014 #include <QJsonArray>
0015 #include <QJsonObject>
0016 #include <QJsonValue>
0017 #include <QSharedData>
0018 
0019 #include <algorithm>
0020 
0021 namespace KGAPI2::People
0022 {
0023 class RelationshipStatus::Private : public QSharedData
0024 {
0025 public:
0026     explicit Private() = default;
0027     Private(const Private &) = default;
0028     Private(Private &&) noexcept = delete;
0029     Private &operator=(const Private &) = delete;
0030     Private &operator=(Private &&) noexcept = delete;
0031     ~Private() = default;
0032 
0033     bool operator==(const Private &other) const
0034     {
0035         return value == other.value && formattedValue == other.formattedValue && metadata == other.metadata;
0036     }
0037 
0038     bool operator!=(const Private &other) const
0039     {
0040         return !(*this == other);
0041     }
0042 
0043     QString value{};
0044     QString formattedValue{};
0045     FieldMetadata metadata{};
0046 };
0047 
0048 RelationshipStatus::RelationshipStatus()
0049     : d(new Private)
0050 {
0051 }
0052 
0053 RelationshipStatus::RelationshipStatus(const RelationshipStatus &) = default;
0054 RelationshipStatus::RelationshipStatus(RelationshipStatus &&) noexcept = default;
0055 RelationshipStatus &RelationshipStatus::operator=(const RelationshipStatus &) = default;
0056 RelationshipStatus &RelationshipStatus::operator=(RelationshipStatus &&) noexcept = default;
0057 RelationshipStatus::~RelationshipStatus() = default;
0058 
0059 bool RelationshipStatus::operator==(const RelationshipStatus &other) const
0060 {
0061     return *d == *other.d;
0062 }
0063 
0064 bool RelationshipStatus::operator!=(const RelationshipStatus &other) const
0065 {
0066     return !(*this == other);
0067 }
0068 
0069 QString RelationshipStatus::value() const
0070 {
0071     return d->value;
0072 }
0073 
0074 void RelationshipStatus::setValue(const QString &value)
0075 {
0076     d->value = value;
0077 }
0078 QString RelationshipStatus::formattedValue() const
0079 {
0080     return d->formattedValue;
0081 }
0082 FieldMetadata RelationshipStatus::metadata() const
0083 {
0084     return d->metadata;
0085 }
0086 
0087 void RelationshipStatus::setMetadata(const FieldMetadata &value)
0088 {
0089     d->metadata = value;
0090 }
0091 
0092 RelationshipStatus RelationshipStatus::fromJSON(const QJsonObject &obj)
0093 {
0094     Q_UNUSED(obj);
0095     return RelationshipStatus();
0096 }
0097 
0098 QJsonValue RelationshipStatus::toJSON() const
0099 {
0100     QJsonObject obj;
0101 
0102     PeopleUtils::addValueToJsonObjectIfValid(obj, "value", d->value);
0103     PeopleUtils::addValueToJsonObjectIfValid(obj, "formattedValue", d->formattedValue);
0104     // Skip, field metadata is only useful for receiving -> PeopleUtils::addValueToJsonObjectIfValid(obj, "metadata", d->metadata.toJSON());
0105     return obj;
0106 }
0107 
0108 } // namespace KGAPI2::People