// Path: app/src/main/java/com/example/offline/domain/LocalCommentRepository.java
// public interface LocalCommentRepository {
//     Single<Comment> add(long photoId, String commentText);
//     Completable update(Comment comment);
//     Completable delete(Comment comment);
//     Flowable<List<Comment>> getComments(long photoId);
// }
// 
// Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
// 
//     @PrimaryKey(autoGenerate = true)
//     private long id;
// 
//     @ColumnInfo(name = "photo_id")
//     private long photoId;
// 
//     @SerializedName("body")
//     @ColumnInfo(name = "comment_text")
//     private String commentText;
// 
//     @ColumnInfo(name = "timestamp")
//     private long timestamp;
// 
//     @ColumnInfo(name = "sync_pending")
//     private boolean syncPending;
// 
//     public long getId() {
//         return id;
//     }
// 
//     public long getPhotoId() {
//         return photoId;
//     }
// 
//     public String getCommentText() {
//         return commentText;
//     }
// 
//     public long getTimestamp() {
//         return timestamp;
//     }
// 
//     public boolean isSyncPending() {
//         return syncPending;
//     }
// 
//     @Ignore
//     public Comment(long photoId, String commentText) {
//         this.photoId = photoId;
//         this.commentText = commentText;
//         this.timestamp = System.currentTimeMillis();
//         this.syncPending = true;
//     }
// 
//     public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
//         this.id = id;
//         this.photoId = photoId;
//         this.commentText = commentText;
//         this.timestamp = timestamp;
//         this.syncPending = syncPending;
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
//     }
// }
// 
// Path: app/src/main/java/com/example/offline/model/CommentUtils.java
// public class CommentUtils {
//     public static Comment clone(Comment from, boolean syncPending) {
//         return new Comment(from.getId(), from.getPhotoId(), from.getCommentText(),
//                 from.getTimestamp(), syncPending);
//     }
// 
//     public static Comment clone(Comment from, long id) {
//         return new Comment(id, from.getPhotoId(), from.getCommentText(),
//                 from.getTimestamp(), from.isSyncPending());
//     }
// }


import com.example.offline.domain.LocalCommentRepository;
import com.example.offline.model.Comment;
import com.example.offline.model.CommentUtils;
import java.util.List;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Single;
import timber.log.Timber;
package com.example.offline.data;




public class LocalCommentDataStore implements LocalCommentRepository {

    private final CommentDao commentDao;

    public LocalCommentDataStore(CommentDao commentDao) {
        this.commentDao = commentDao;
    }

    /**
     * Adds a comment to a given photo
     */
    public Single<Comment> add(long photoId, String commentText) {
        Timber.d("creating comment for photo id %s, comment text %s", photoId, commentText);
        Comment comment = new Comment(photoId, commentText);

        return Single.fromCallable(() -> {
            long rowId = commentDao.add(comment);
            Timber.d("comment stored " + rowId);
// Path: app/src/main/java/com/example/offline/domain/LocalCommentRepository.java
// public interface LocalCommentRepository {
//     Single<Comment> add(long photoId, String commentText);
//     Completable update(Comment comment);
//     Completable delete(Comment comment);
//     Flowable<List<Comment>> getComments(long photoId);
// }
// 
// Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
// 
//     @PrimaryKey(autoGenerate = true)
//     private long id;
// 
//     @ColumnInfo(name = "photo_id")
//     private long photoId;
// 
//     @SerializedName("body")
//     @ColumnInfo(name = "comment_text")
//     private String commentText;
// 
//     @ColumnInfo(name = "timestamp")
//     private long timestamp;
// 
//     @ColumnInfo(name = "sync_pending")
//     private boolean syncPending;
// 
//     public long getId() {
//         return id;
//     }
// 
//     public long getPhotoId() {
//         return photoId;
//     }
// 
//     public String getCommentText() {
//         return commentText;
//     }
// 
//     public long getTimestamp() {
//         return timestamp;
//     }
// 
//     public boolean isSyncPending() {
//         return syncPending;
//     }
// 
//     @Ignore
//     public Comment(long photoId, String commentText) {
//         this.photoId = photoId;
//         this.commentText = commentText;
//         this.timestamp = System.currentTimeMillis();
//         this.syncPending = true;
//     }
// 
//     public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
//         this.id = id;
//         this.photoId = photoId;
//         this.commentText = commentText;
//         this.timestamp = timestamp;
//         this.syncPending = syncPending;
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
//     }
// }
// 
// Path: app/src/main/java/com/example/offline/model/CommentUtils.java
// public class CommentUtils {
//     public static Comment clone(Comment from, boolean syncPending) {
//         return new Comment(from.getId(), from.getPhotoId(), from.getCommentText(),
//                 from.getTimestamp(), syncPending);
//     }
// 
//     public static Comment clone(Comment from, long id) {
//         return new Comment(id, from.getPhotoId(), from.getCommentText(),
//                 from.getTimestamp(), from.isSyncPending());
//     }
// }


// Path: app/src/main/java/com/example/offline/data/LocalCommentDataStore.java
import com.example.offline.domain.LocalCommentRepository;
import com.example.offline.model.Comment;
import com.example.offline.model.CommentUtils;
import java.util.List;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Single;
import timber.log.Timber;

package com.example.offline.data;




public class LocalCommentDataStore implements LocalCommentRepository {

    private final CommentDao commentDao;

    public LocalCommentDataStore(CommentDao commentDao) {
        this.commentDao = commentDao;
    }

    /**
     * Adds a comment to a given photo
     */
    public Single<Comment> add(long photoId, String commentText) {
        Timber.d("creating comment for photo id %s, comment text %s", photoId, commentText);
        Comment comment = new Comment(photoId, commentText);

        return Single.fromCallable(() -> {
            long rowId = commentDao.add(comment);
            Timber.d("comment stored " + rowId);
            return CommentUtils.clone(comment, rowId);