import type { Permission } from "@/shared/types/permissions"

/** A role row as stored in the `roles` table. */
export interface RoleRecord {
  id: string
  name: string
  description: string | null
  isSystem: boolean
  isEnabled: boolean
  createdAt: Date
  updatedAt: Date
}

/** A role with its permission list and aggregate counts, for list/detail views. */
export interface RoleWithStats extends RoleRecord {
  /** Number of permissions assigned to this role. */
  permissionCount: number
  /** Number of users assigned to this role. */
  userCount: number
}

/** A role with its full permission list, for the detail/edit view. */
export interface RoleDetail extends RoleRecord {
  permissions: Permission[]
  /** Number of users assigned to this role (for impact notices). */
  userCount: number
}

/** Input for creating a new role. */
export interface CreateRoleInput {
  name: string
  description?: string | null
}

/** Input for updating an existing role. `name` is ignored for the `admin` role. */
export interface UpdateRoleInput {
  name?: string
  description?: string | null
}

/** A user-role assignment row, for the assignment management view. */
export interface UserRoleAssignment {
  userId: string
  userName: string | null
  userEmail: string
  roleNames: string[]
  createdAt: Date
}

/** Paginated result wrapper (mirrors the audit module's pattern). */
export interface PaginatedResult<T> {
  items: T[]
  page: number
  pageSize: number
  total: number
  totalPages: number
}
