/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
import 'package:copy_with_extension/copy_with_extension.dart';
import 'package:drift/drift.dart';
import 'package:fast_equatable/fast_equatable.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:weblibre/features/web_feed/data/database/definitions.drift.dart';
import 'package:weblibre/features/web_feed/data/models/feed_author.dart';
import 'package:weblibre/features/web_feed/data/models/feed_category.dart';
import 'package:weblibre/features/web_feed/data/models/feed_link.dart';
part 'feed_article.g.dart';
@JsonSerializable()
@CopyWith()
class FeedArticle with FastEquatable implements Insertable {
final String id;
final Uri feedId;
final DateTime fetched;
final DateTime? created;
final DateTime? updated;
final DateTime? lastRead;
final String? title;
final List? authors;
final List? tags;
final List? links;
final String? summaryHtml;
final String? summaryMarkdown;
final String? summaryPlain;
final String? contentHtml;
final String? contentMarkdown;
final String? contentPlain;
//Derived by view from feed table, should not get inserted
final Uri? icon;
final Uri? siteLink;
FeedArticle({
required this.id,
required this.feedId,
required this.fetched,
this.created,
this.updated,
this.lastRead,
this.title,
this.authors,
this.tags,
this.links,
this.summaryHtml,
this.summaryMarkdown,
this.summaryPlain,
this.contentHtml,
this.contentMarkdown,
this.contentPlain,
this.icon,
this.siteLink,
});
factory FeedArticle.fromJson(Map json) =>
_$FeedArticleFromJson(json);
Map toJson() => _$FeedArticleToJson(this);
@override
Map toColumns(bool nullToAbsent) {
final map = {};
map['id'] = Variable(id);
{
map['feed_id'] = Variable(Article.$converterfeedId.toSql(feedId));
}
map['fetched'] = Variable(fetched);
if (!nullToAbsent || created != null) {
map['created'] = Variable(created);
}
if (!nullToAbsent || updated != null) {
map['updated'] = Variable(updated);
}
if (!nullToAbsent || lastRead != null) {
map['last_read'] = Variable(lastRead);
}
if (!nullToAbsent || title != null) {
map['title'] = Variable(title);
}
if (!nullToAbsent || authors != null) {
map['authors'] = Variable(
Article.$converterauthorsn.toSql(authors),
);
}
if (!nullToAbsent || tags != null) {
map['tags'] = Variable(Article.$convertertagsn.toSql(tags));
}
if (!nullToAbsent || links != null) {
map['links'] = Variable(Article.$converterlinksn.toSql(links));
}
if (!nullToAbsent || summaryHtml != null) {
map['summaryHtml'] = Variable(summaryHtml);
}
if (!nullToAbsent || summaryMarkdown != null) {
map['summaryMarkdown'] = Variable(summaryMarkdown);
}
if (!nullToAbsent || summaryPlain != null) {
map['summaryPlain'] = Variable(summaryPlain);
}
if (!nullToAbsent || contentHtml != null) {
map['contentHtml'] = Variable(contentHtml);
}
if (!nullToAbsent || contentMarkdown != null) {
map['contentMarkdown'] = Variable(contentMarkdown);
}
if (!nullToAbsent || contentPlain != null) {
map['contentPlain'] = Variable(contentPlain);
}
return map;
}
@override
List