import apiClient from './index.js' import { apiEndpoints as E } from './endpoints.js' import { paginatedGet } from './paginate.js' import { apiCall } from './apiError.js' import { toApiBool } from './boolCodec.js' // Get subject list export const getSubjects = () => paginatedGet(apiClient, E.SUBJECTS.LIST) const buildPayload = (s) => ({ subject_name: s.subject_name || '', enabled_flag: toApiBool(s.enabled_flag ?? 'Y'), primary_flag: toApiBool(s.primary_flag ?? 'N'), calendar_color: s.calendar_color || '', sort_sequence: parseInt(s.sort_sequence) || 0, tenant_id: s.tenant_id || 1, }) // Create subject export const createSubject = (data) => apiCall('POST', E.SUBJECTS.CREATE, { data: buildPayload(data) }, 'Failed to create subject') // Update subject information export const updateSubject = (subjectId, data) => apiCall( 'PATCH', E.SUBJECTS.UPDATE(subjectId), { data: buildPayload(data) }, 'Failed to update subject', ) // Delete subject export const deleteSubject = (subjectId) => apiCall('DELETE', E.SUBJECTS.DELETE(subjectId), null, 'Failed to delete subject')