import api from './api';

export const postService = {
  getPosts: (dateFrom, dateTo) => {
    const params = {};
    if (dateFrom) params.date_from = dateFrom;
    if (dateTo) params.date_to = dateTo;
    return api.get('/posts', { params }).then(r => r.data);
  },

  createPost: (data) => api.post('/posts', data).then(r => r.data),

  getPost: (id) => api.get(`/posts/${id}`).then(r => r.data),

  updatePost: (id, data) => api.put(`/posts/${id}`, data).then(r => r.data),

  deletePost: (id) => api.delete(`/posts/${id}`).then(r => r.data),

  addGenerations: (postId, generationIds) =>
    api.post(`/posts/${postId}/generations`, { generation_ids: generationIds }).then(r => r.data),

  removeGeneration: (postId, generationId) =>
    api.delete(`/posts/${postId}/generations/${generationId}`).then(r => r.data),
};
