// Path: src/main/java/org/ominidi/domain/model/Feed.java
// @Getter
// public class Feed<Post> implements Iterable<Post> {
//     private final List<Post> posts;
//     private final String nextUrl;
//     private final String prevUrl;
//     private final Integer size;
// 
//     public Feed(List<Post> posts, String nextUrl, String prevUrl) {
//         this.posts = posts;
//         this.size = posts.size();
//         this.nextUrl = nextUrl;
//         this.prevUrl = prevUrl;
//     }
// 
//     @Override
//     public Iterator<Post> iterator() {
//         return posts.iterator();
//     }
// 
//     public Integer size() {
//         return posts.size();
//     }
// }
// 
// Path: src/main/java/org/ominidi/domain/model/Post.java
// @Getter
// public class Post {
//     private final String id;
//     private final String objectId;
//     private final String createdTime;
//     private final String type;
//     private final String link;
//     private final String permalinkUrl;
//     private final String picture;
//     private final String fullPicture;
//     private final String message;
// 
//     public Post(
//             String id,
//             String objectId,
//             String createdTime,
//             String type,
//             String link,
//             String permalinkUrl,
//             String picture,
//             String fullPicture,
//             String message
//     ) {
//         this.id = id;
//         this.objectId = objectId;
//         this.createdTime = createdTime;
//         this.type = type;
//         this.link = link;
//         this.permalinkUrl = permalinkUrl;
//         this.picture = picture;
//         this.fullPicture = fullPicture;
//         this.message = message;
//     }
// }
// 
// Path: src/main/java/org/ominidi/facebook/exception/ConnectionException.java
// public class ConnectionException extends Exception {
//     public ConnectionException(String message) {
//         super(message);
//     }
// 
//     public ConnectionException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public ConnectionException(Throwable cause) {
//         super(cause);
//     }
// }
// 
// Path: src/main/java/org/ominidi/facebook/mapper/FeedMapper.java
// @Component
// public class FeedMapper implements FromType<Connection<JsonObject>, Feed<Post>> {
//     private PostMapper postMapper;
// 
//     @Autowired
//     public FeedMapper(PostMapper postMapper) {
//         this.postMapper = postMapper;
//     }
// 
//     @Override
//     public Feed<Post> fromType(Connection<JsonObject> toMap) {
//         List<Post> posts = toMap.getData().stream().map(jsonObject -> new Post(
//                 jsonObject.getString("id", null),
//                 jsonObject.getString("object_id", null),
//                 jsonObject.getString("created_time", null),
//                 jsonObject.getString("type", null),
//                 jsonObject.getString("link", null),
//                 jsonObject.getString("permalink_url", null),
//                 jsonObject.getString("picture", null),
//                 jsonObject.getString("full_picture", null),
//                 jsonObject.getString("message", null)
//         )).collect(Collectors.toList());
// 
//         return new Feed<>(posts, toMap.getNextPageUrl(), toMap.getPreviousPageUrl());
//     }
// }
// 
// Path: src/main/java/org/ominidi/facebook/mapper/PostMapper.java
// @Component
// public class PostMapper implements FromType<JsonObject, Post> {
// 
//     @Override
//     public Post fromType(JsonObject jsonObject) {
//         return new Post(
//                 jsonObject.getString("id", null),
//                 jsonObject.getString("object_id", null),
//                 jsonObject.getString("created_time", null),
//                 jsonObject.getString("type", null),
//                 jsonObject.getString("link", null),
//                 jsonObject.getString("permalink_url", null),
//                 jsonObject.getString("picture", null),
//                 jsonObject.getString("full_picture", null),
//                 jsonObject.getString("message", null)
//         );
//     }
// }
// 
// Path: src/main/java/org/ominidi/facebook/repository/ConnectionAware.java
// public interface ConnectionAware {
//     Connection<JsonObject> getConnection() throws ConnectionException;
//     Connection<JsonObject> getConnection(String connectionPageUrl) throws ConnectionException;
//     JsonObject getObject(String id) throws ConnectionException;
// }


import org.ominidi.domain.model.Feed;
import org.ominidi.domain.model.Post;
import org.ominidi.facebook.exception.ConnectionException;
import org.ominidi.facebook.mapper.FeedMapper;
import org.ominidi.facebook.mapper.PostMapper;
import org.ominidi.facebook.repository.ConnectionAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Optional;


    @Autowired
    public PageFeedService(ConnectionAware pageFeed, FeedMapper feedMapper, PostMapper postMapper) {
        this.pageFeed = pageFeed;
        this.feedMapper = feedMapper;
        this.postMapper = postMapper;
    }

    @Override
    public Optional<Feed<Post>> getFeed() {
        try {
            return Optional.of(feedMapper.fromType(pageFeed.getConnection()));
        } catch (ConnectionException e) {
            return Optional.empty();
        }
    }

    @Override
    public Optional<Feed<Post>> getFeed(String feedUrl) {
        try {
            return Optional.of(feedMapper.fromType(pageFeed.getConnection(feedUrl)));
        } catch (ConnectionException e) {
            return Optional.empty();
        }
    }

    @Override
    public Optional<Post> getPostById(String id) {
        try {
            return Optional.of(postMapper.fromType(pageFeed.getObject(id)));

// Path: src/main/java/org/ominidi/domain/model/Feed.java
// @Getter
// public class Feed<Post> implements Iterable<Post> {
//     private final List<Post> posts;
//     private final String nextUrl;
//     private final String prevUrl;
//     private final Integer size;
// 
//     public Feed(List<Post> posts, String nextUrl, String prevUrl) {
//         this.posts = posts;
//         this.size = posts.size();
//         this.nextUrl = nextUrl;
//         this.prevUrl = prevUrl;
//     }
// 
//     @Override
//     public Iterator<Post> iterator() {
//         return posts.iterator();
//     }
// 
//     public Integer size() {
//         return posts.size();
//     }
// }
// 
// Path: src/main/java/org/ominidi/domain/model/Post.java
// @Getter
// public class Post {
//     private final String id;
//     private final String objectId;
//     private final String createdTime;
//     private final String type;
//     private final String link;
//     private final String permalinkUrl;
//     private final String picture;
//     private final String fullPicture;
//     private final String message;
// 
//     public Post(
//             String id,
//             String objectId,
//             String createdTime,
//             String type,
//             String link,
//             String permalinkUrl,
//             String picture,
//             String fullPicture,
//             String message
//     ) {
//         this.id = id;
//         this.objectId = objectId;
//         this.createdTime = createdTime;
//         this.type = type;
//         this.link = link;
//         this.permalinkUrl = permalinkUrl;
//         this.picture = picture;
//         this.fullPicture = fullPicture;
//         this.message = message;
//     }
// }
// 
// Path: src/main/java/org/ominidi/facebook/exception/ConnectionException.java
// public class ConnectionException extends Exception {
//     public ConnectionException(String message) {
//         super(message);
//     }
// 
//     public ConnectionException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public ConnectionException(Throwable cause) {
//         super(cause);
//     }
// }
// 
// Path: src/main/java/org/ominidi/facebook/mapper/FeedMapper.java
// @Component
// public class FeedMapper implements FromType<Connection<JsonObject>, Feed<Post>> {
//     private PostMapper postMapper;
// 
//     @Autowired
//     public FeedMapper(PostMapper postMapper) {
//         this.postMapper = postMapper;
//     }
// 
//     @Override
//     public Feed<Post> fromType(Connection<JsonObject> toMap) {
//         List<Post> posts = toMap.getData().stream().map(jsonObject -> new Post(
//                 jsonObject.getString("id", null),
//                 jsonObject.getString("object_id", null),
//                 jsonObject.getString("created_time", null),
//                 jsonObject.getString("type", null),
//                 jsonObject.getString("link", null),
//                 jsonObject.getString("permalink_url", null),
//                 jsonObject.getString("picture", null),
//                 jsonObject.getString("full_picture", null),
//                 jsonObject.getString("message", null)
//         )).collect(Collectors.toList());
// 
//         return new Feed<>(posts, toMap.getNextPageUrl(), toMap.getPreviousPageUrl());
//     }
// }
// 
// Path: src/main/java/org/ominidi/facebook/mapper/PostMapper.java
// @Component
// public class PostMapper implements FromType<JsonObject, Post> {
// 
//     @Override
//     public Post fromType(JsonObject jsonObject) {
//         return new Post(
//                 jsonObject.getString("id", null),
//                 jsonObject.getString("object_id", null),
//                 jsonObject.getString("created_time", null),
//                 jsonObject.getString("type", null),
//                 jsonObject.getString("link", null),
//                 jsonObject.getString("permalink_url", null),
//                 jsonObject.getString("picture", null),
//                 jsonObject.getString("full_picture", null),
//                 jsonObject.getString("message", null)
//         );
//     }
// }
// 
// Path: src/main/java/org/ominidi/facebook/repository/ConnectionAware.java
// public interface ConnectionAware {
//     Connection<JsonObject> getConnection() throws ConnectionException;
//     Connection<JsonObject> getConnection(String connectionPageUrl) throws ConnectionException;
//     JsonObject getObject(String id) throws ConnectionException;
// }


// Path: src/main/java/org/ominidi/facebook/service/PageFeedService.java
import org.ominidi.domain.model.Feed;
import org.ominidi.domain.model.Post;
import org.ominidi.facebook.exception.ConnectionException;
import org.ominidi.facebook.mapper.FeedMapper;
import org.ominidi.facebook.mapper.PostMapper;
import org.ominidi.facebook.repository.ConnectionAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Optional;


    @Autowired
    public PageFeedService(ConnectionAware pageFeed, FeedMapper feedMapper, PostMapper postMapper) {
        this.pageFeed = pageFeed;
        this.feedMapper = feedMapper;
        this.postMapper = postMapper;
    }

    @Override
    public Optional<Feed<Post>> getFeed() {
        try {
            return Optional.of(feedMapper.fromType(pageFeed.getConnection()));
        } catch (ConnectionException e) {
            return Optional.empty();
        }
    }

    @Override
    public Optional<Feed<Post>> getFeed(String feedUrl) {
        try {
            return Optional.of(feedMapper.fromType(pageFeed.getConnection(feedUrl)));
        } catch (ConnectionException e) {
            return Optional.empty();
        }
    }

    @Override
    public Optional<Post> getPostById(String id) {
        try {
            return Optional.of(postMapper.fromType(pageFeed.getObject(id)));

        } catch (ConnectionException e) {
