/**
 * Team Capacity Calculator
 *
 * Pure utility for calculating team member workload utilization
 * and capacity status used by the capacity API route.
 */

export interface CapacityInput {
  userId: number
  userName: string
  activeTasks: number
  estimatedHours: number
  videosInPipeline: number
  availableHoursPerWeek: number
}

export interface CapacityResult {
  userId: number
  userName: string
  activeTasks: number
  estimatedHours: number
  videosInPipeline: number
  availableHoursPerWeek: number
  utilization: number // 0-100+
  status: 'green' | 'yellow' | 'red'
}

function calculateCapacity(input: CapacityInput): CapacityResult {
  const utilization =
    input.availableHoursPerWeek > 0
      ? Math.round((input.estimatedHours / input.availableHoursPerWeek) * 100)
      : 0

  let status: CapacityResult['status'] = 'green'
  if (utilization > 90) {
    status = 'red'
  } else if (utilization > 70) {
    status = 'yellow'
  }

  return { ...input, utilization, status }
}

export { calculateCapacity }
