import { baseClient } from './base.js';

export const linksApi = {
  list(workspaceId, params = {}) {
    const query = new URLSearchParams(params).toString();
    const path = `/workspaces/${workspaceId}/links${query ? `?${query}` : ''}`;
    return baseClient.get(path);
  },

  create(workspaceId, data) {
    return baseClient.post(`/workspaces/${workspaceId}/links`, data);
  },

  get(workspaceId, id) {
    return baseClient.get(`/workspaces/${workspaceId}/links/${id}`);
  },

  update(workspaceId, id, data) {
    return baseClient.put(`/workspaces/${workspaceId}/links/${id}`, data);
  },

  delete(workspaceId, id) {
    return baseClient.delete(`/workspaces/${workspaceId}/links/${id}`);
  },

  restore(workspaceId, id) {
    return baseClient.post(`/workspaces/${workspaceId}/links/${id}/restore`);
  },

  bulkCreate(workspaceId, links) {
    return baseClient.post(`/workspaces/${workspaceId}/links/bulk`, { links });
  },

  getAnalytics(workspaceId, linkId, period = '7d', startDate = null, endDate = null) {
    const params = new URLSearchParams();
    if (startDate && endDate) {
      params.set('startDate', startDate);
      params.set('endDate', endDate);
    } else {
      params.set('period', period);
    }
    return baseClient.get(`/workspaces/${workspaceId}/links/${linkId}/analytics?${params.toString()}`);
  },
};
