#ifndef AUTHORATTRIBUTION_H #define AUTHORATTRIBUTION_H #include #include #include struct StructuredAuthor { std::optional firstName; std::optional middleName; std::optional lastName; std::optional nickname; bool operator==(const StructuredAuthor &other) const { return firstName == other.firstName && middleName == other.middleName && lastName == other.lastName && nickname == other.nickname; } bool operator!=(const StructuredAuthor &other) const { return !(*this == other); } }; struct CreatorItem { std::optional roleCode; QString name; bool operator==(const CreatorItem &other) const { return roleCode == other.roleCode && name == other.name; } bool operator!=(const CreatorItem &other) const { return !(*this == other); } }; enum class MetadataStatus { Unparsed, Parsed }; struct BookEntity { QString filePath; bool isActive = true; bool operator==(const BookEntity &other) const { return filePath == other.filePath && isActive == other.isActive; } bool operator!=(const BookEntity &other) const { return !(*this == other); } }; struct BookMetadata { BookEntity book; MetadataStatus status = MetadataStatus::Unparsed; QList rawDcCreators; QList rawStructuredAuthors; std::optional authorAttribution; bool operator==(const BookMetadata &other) const { return book == other.book && status == other.status && rawDcCreators == other.rawDcCreators && rawStructuredAuthors == other.rawStructuredAuthors && authorAttribution == other.authorAttribution; } bool operator!=(const BookMetadata &other) const { return !(*this == other); } }; class AuthorAttributionService { public: virtual ~AuthorAttributionService() = default; virtual QString resolveAttribution(const QString &filePath) = 0; }; class AuthorAttribution { public: static QString mapRole(const std::optional &roleCode); static QString formatCreators(const QList &creators); static QString formatStructuredAuthors(const QList &authors); static BookMetadata loadMetadata(const BookEntity &book, const QList &creators, const QList &authors); static bool parseMetadataWithDcCreators(BookMetadata &metadata); static bool parseMetadataFallbackToStructuredAuthors(BookMetadata &metadata); static bool parseMetadata(BookMetadata &metadata); }; class BookMetadataSurface : public AuthorAttributionService { public: explicit BookMetadataSurface(const BookMetadata &metadata, bool engineActive = true); bool isAccessible() const; QString filePath() const; std::optional authorAttribution() const; bool canProvideLoadMetadata() const; bool canProvideParseMetadata() const; void loadMetadata(const QList &creators, const QList &authors); bool parseMetadata(); QString resolveAttribution(const QString &filePath) override; const BookMetadata &metadata() const; void setMetadata(const BookMetadata &metadata); void setEngineActive(bool active); private: BookMetadata m_metadata; bool m_engineActive; }; #endif // AUTHORATTRIBUTION_H