export interface Permission {
  id: number;
  name: string;
  code: string;
  description: string;
  category: string;
}

export interface Role {
  id: number;
  name: string;
  description: string;
  entity_id: number | null;
  entity_name: string;
  permission_ids: number[];
  permissions: Permission[];
  user_count: number;
  permission_codes?: string[];
}

export interface RoleCreateRequest {
  name: string;
  description?: string;
  entity_id?: number;
  permission_ids?: number[];
}

export interface PermissionCreateRequest {
  name: string;
  code: string;
  description?: string;
  category?: string;
}

export interface AuthorityMatrixData {
  roles: AuthorityMatrixRole[];
  categories: Record<string, Permission[]>;
  total_roles: number;
  total_permissions: number;
}

export interface AuthorityMatrixRole {
  id: number;
  name: string;
  description: string;
  granted_permission_ids: number[];
}

// ── User-Role types ──

export interface UserWithRoles {
  id: number;
  name: string;
  login: string;
  email: string;
  active: boolean;
  roles: { id: number; name: string }[];
  role_ids: number[];
  effective_permission_count: number;
}

export interface UserRoleDetail {
  user: { id: number; name: string; login: string; email: string };
  roles: { id: number; name: string; description: string; assigned: boolean; permission_count: number }[];
  effective_permissions: Permission[];
}

export interface UserAuthorityMatrixData {
  users: UserAuthorityMatrixUser[];
  categories: Record<string, Permission[]>;
  total_users: number;
  total_permissions: number;
}

export interface UserAuthorityMatrixUser {
  id: number;
  name: string;
  login: string;
  roles: { id: number; name: string }[];
  granted_permission_ids: number[];
}
