/**
 * File: admin.ts
 * Created by: AI Assistant
 * Date: 2025-12-01
 * Purpose: Utility functions for admin role checking
 * Part of: kreatiVortex - Platform Pembelajaran Tari Online
 */

/**
 * Check if user has admin privileges
 * @param userProfile - User profile object with role information
 * @returns boolean - true if user is ADMIN or PENDIDIK, false otherwise
 */
export function isAdmin(userProfile: any): boolean {
  if (!userProfile || !userProfile.role) {
    return false;
  }

  const adminRoles = ['ADMIN', 'PENDIDIK'];
  return adminRoles.includes(userProfile.role.name);
}

/**
 * Check if user can upload videos
 * @param userProfile - User profile object with role information
 * @returns boolean - true if user can upload videos, false otherwise
 */
export function canUploadVideos(userProfile: any): boolean {
  return !!userProfile;
}

/**
 * Check if user can delete any video (not just their own)
 * @param userProfile - User profile object with role information
 * @returns boolean - true if user is ADMIN, false otherwise
 */
export function canDeleteAnyVideo(userProfile: any): boolean {
  if (!userProfile || !userProfile.role) {
    return false;
  }

  return userProfile.role.name === 'ADMIN';
}

/**
 * Check if user can edit a specific video
 * @param userProfile - User profile object with role information
 * @param videoUploaderId - ID of the user who uploaded the video
 * @returns boolean - true if user can edit the video, false otherwise
 */
export function canEditVideo(userProfile: any, videoUploaderId: string): boolean {
  if (!userProfile || !userProfile.id || !userProfile.role) {
    return false;
  }

  return isAdmin(userProfile) || userProfile.id === videoUploaderId;
}

/**
 * Check if user can delete a specific video
 * @param userProfile - User profile object with role information
 * @param videoUploaderId - ID of the user who uploaded the video
 * @returns boolean - true if user can delete the video, false otherwise
 */
export function canDeleteVideo(userProfile: any, videoUploaderId: string): boolean {
  if (!userProfile || !userProfile.id || !userProfile.role) {
    return false;
  }

  return canDeleteAnyVideo(userProfile) || userProfile.id === videoUploaderId;
}