import type { HydraCollection } from '~/utils/api'
import { extractHydraMembers } from '~/utils/api'

export type Permission = {
    id: number
    '@id'?: string
    code: string
    label: string
    module: string
    orphan?: boolean
}

export function usePermissionService() {
    const api = useApi()

    async function list(): Promise<Permission[]> {
        const data = await api.get<HydraCollection<Permission>>('/permissions')
        return extractHydraMembers(data)
    }

    return { list }
}
