import { apiClient } from '@/lib/api-client';
import type {
  CloneCrmRoleProfilePayload,
  CrmRoleProfileRecord,
  CrmRoleProfilesResponse,
  UpdateCrmRoleProfilePayload
} from './types';

export async function getCrmRoleProfiles() {
  return apiClient<CrmRoleProfilesResponse>('/crm/settings/roles');
}

export async function updateCrmRoleProfile(code: string, payload: UpdateCrmRoleProfilePayload) {
  return apiClient<{ success: boolean; role: CrmRoleProfileRecord }>(`/crm/settings/roles/${code}`, {
    method: 'PATCH',
    body: JSON.stringify(payload)
  });
}

export async function cloneCrmRoleProfile(sourceCode: string, payload: CloneCrmRoleProfilePayload) {
  return apiClient<{ success: boolean; role: CrmRoleProfileRecord }>(
    `/crm/settings/roles/${sourceCode}/clone`,
    {
      method: 'POST',
      body: JSON.stringify(payload)
    }
  );
}
