import axiosInstance from '@/utills/axiosInstance';
import type { SlaRule, SlaWorkingHoursPayload } from './interface';

export async function getFeatureControls(): Promise<any> {
  return await axiosInstance.get('/api/v1/masters/feature-controls');
}

export async function updateFeatureControlStatus(id: number, is_enabled: boolean): Promise<any> {
  return await axiosInstance.patch(`/api/v1/masters/feature-controls/${id}`, { is_enabled });
}

// Each SLA's working hours and weekly closed days (the 30-minute and the overdue reassignment keep their own).
export async function getSlaSettings(): Promise<any> {
  return await axiosInstance.get('/api/v1/auto-lead-assignment/sla-settings');
}

export async function updateSlaSettings(payload: SlaWorkingHoursPayload): Promise<any> {
  return await axiosInstance.put('/api/v1/auto-lead-assignment/sla-settings', payload);
}

// SLA holidays, kept per SLA: the days its reassignment does not run.
export async function getSlaHolidays(): Promise<any> {
  return await axiosInstance.get('/api/v1/auto-lead-assignment/sla-holidays');
}

export async function addSlaHolidays(payload: { dates: string[]; reason?: string; rules?: SlaRule[] }): Promise<any> {
  return await axiosInstance.post('/api/v1/auto-lead-assignment/sla-holidays', payload);
}

export async function removeSlaHoliday(id: number): Promise<any> {
  return await axiosInstance.delete(`/api/v1/auto-lead-assignment/sla-holidays/${id}`);
}
