import api from './api';

export interface Role {
    id: string;
    name: string;
    description?: string;
    permissions: any;
    isSystem: boolean;
    _count?: {
        users: number;
    };
}

export interface CreateRoleData {
    name: string;
    description?: string;
    permissions: any;
}

export const rolesApi = {
    getAll: async () => {
        const response = await api.get<Role[]>('/roles');
        return response.data;
    },

    create: async (data: CreateRoleData) => {
        const response = await api.post<Role>('/roles', data);
        return response.data;
    },

    update: async (id: string, data: Partial<CreateRoleData>) => {
        const response = await api.patch<Role>(`/roles/${id}`, data);
        return response.data;
    },

    delete: async (id: string) => {
        await api.delete(`/roles/${id}`);
    }
};
