import axios from 'axios'; const apiClient = axios.create({ baseURL: '/api', headers: { 'Content-Type': 'application/json' }, }); // ── Channels ────────────────────────────────────────────────────────────── export const fetchChannels = async () => (await apiClient.get('/channel/')).data; export const createChannel = async (payload) => (await apiClient.post('/channel/', payload)).data; export const updateChannel = async (id, payload) => (await apiClient.patch(`/channel/${id}`, payload)).data; export const deleteChannel = async (id) => { await apiClient.delete(`/channel/${id}`); }; // Channel program data export const fetchChannelNow = async (channelId) => (await apiClient.get(`/channel/${channelId}/now`)).data; export const fetchChannelAirings = async (channelId, hours = 4) => (await apiClient.get(`/channel/${channelId}/airings?hours=${hours}`)).data; // Channel ↔ Source assignments export const fetchChannelSources = async (channelId) => (await apiClient.get(`/channel/${channelId}/sources`)).data; export const assignSourceToChannel = async (channelId, payload) => (await apiClient.post(`/channel/${channelId}/sources`, payload)).data; export const removeSourceFromChannel = async (channelId, ruleId) => { await apiClient.delete(`/channel/${channelId}/sources/${ruleId}`); }; // ── Schedule ────────────────────────────────────────────────────────────── export const fetchTemplates = async () => (await apiClient.get('/schedule/template/')).data; export const createTemplate = async (payload) => (await apiClient.post('/schedule/template/', payload)).data; export const deleteTemplate = async (id) => { await apiClient.delete(`/schedule/template/${id}`); }; export const generateScheduleToday = async (channelId) => (await apiClient.post(`/schedule/generate-today/${channelId}`)).data; export const fetchTemplateBlocks = async (templateId) => (await apiClient.get(`/schedule/template/${templateId}/blocks`)).data; export const createTemplateBlock = async (payload) => (await apiClient.post('/schedule/block/', payload)).data; export const deleteTemplateBlock = async (blockId) => (await apiClient.delete(`/schedule/block/${blockId}`)).data; // Legacy – used by guide export const fetchScheduleGenerations = async (channelId) => (await apiClient.post(`/schedule/generate/${channelId}`)).data; // ── Media Sources (YouTube / local) ─────────────────────────────────────── export const fetchSources = async () => (await apiClient.get('/sources/')).data; export const createSource = async (payload) => (await apiClient.post('/sources/', payload)).data; export const syncSource = async (sourceId, maxVideos) => { const url = maxVideos ? `/sources/${sourceId}/sync?max_videos=${maxVideos}` : `/sources/${sourceId}/sync`; return (await apiClient.post(url)).data; }; export const deleteSource = async (sourceId) => { await apiClient.delete(`/sources/${sourceId}`); }; // Download controls export const fetchDownloadStatus = async () => (await apiClient.get('/sources/download-status')).data; export const triggerCacheUpcoming = async (hours = 24, pruneOnly = false) => (await apiClient.post(`/sources/cache-upcoming?hours=${hours}&prune_only=${pruneOnly}`)).data; export const downloadItem = async (itemId) => (await apiClient.post(`/sources/${itemId}/download`)).data; export const fetchDownloadProgress = async (itemId) => (await apiClient.get(`/sources/${itemId}/progress`)).data; // ── Libraries ───────────────────────────────────────────────────────────── export const fetchLibraries = async () => (await apiClient.get('/library/')).data; export const fetchCollections = async () => (await apiClient.get('/collections/')).data; // ── Users ───────────────────────────────────────────────────────────────── export const fetchUsers = async () => (await apiClient.get('/user/')).data; export const createUser = async (payload) => (await apiClient.post('/user/', payload)).data; export const updateUser = async (id, payload) => (await apiClient.patch(`/user/${id}`, payload)).data; export const deleteUser = async (id) => { await apiClient.delete(`/user/${id}`); };