import apiClient from './client'
import { UserRoleValue } from './users'

export interface RoleFeature {
  key: string
  label: string
}

export type RolePermissionsMap = Record<UserRoleValue, Record<string, boolean>>

export interface RolePermissionsResponse {
  features: RoleFeature[]
  permissions: RolePermissionsMap
}

export interface RolePermissionsUpdateRequest {
  permissions: RolePermissionsMap
}

export const rolePermissionsApi = {
  async listPermissions(): Promise<RolePermissionsResponse> {
    const { data } = await apiClient.get<RolePermissionsResponse>('/api/v1/role-permissions')
    return data
  },

  async updatePermissions(
    request: RolePermissionsUpdateRequest
  ): Promise<RolePermissionsResponse> {
    const { data } = await apiClient.put<RolePermissionsResponse>(
      '/api/v1/role-permissions',
      request
    )
    return data
  },
}







