#!/usr/bin/env ruby

# Helper functions for generating dynamic text and titles
module TextGenerationHelper
  # Selects a random title from an array
  def self.select_random_title(titles)
    titles.sample
  end

  # Generates quirky comments for peak time usage
  def self.get_peak_time_comment(usage, total_uses)
    return nil if total_uses == 0
    
    # Find peak time period
    times = {
      'Night (0-5)' => usage[:night],
      'Morning (6-11)' => usage[:morning],
      'Afternoon (12-17)' => usage[:afternoon],
      'Evening (18-23)' => usage[:evening]
    }
    
    peak_period, peak_count = times.max_by { |_, count| count }
    
    # Generate quirky comments based on peak time
    case peak_period
    when 'Night (0-5)'
      night_comments = [
        "You're basically a vampire 🦇",
        "3am hits different for you",
        "Night owl energy is unmatched",
        "While others sleep, you party",
        "You own the midnight hours"
      ]
      night_comments.sample
    when 'Morning (6-11)'
      morning_comments = [
        "Rise and grind... literally",
        "Early bird catches the... high",
        "Morning person? More like morning party person",
        "You start your day with a bang",
        "Breakfast of champions energy"
      ]
      morning_comments.sample
    when 'Afternoon (12-17)'
      afternoon_comments = [
        "Lunch break hits different",
        "You're a matinee main character",
        "Afternoon delight enthusiast",
        "Peak productivity hours",
        "You make 2pm look fun"
      ]
      afternoon_comments.sample
    when 'Evening (18-23)'
      evening_comments = [
        "Happy hour is your power hour",
        "You're an evening legend",
        "Prime time performer",
        "Golden hour energy",
        "You close out the day right"
      ]
      evening_comments.sample
    end
  end

  # Generates variation comments for substance streaks
  def self.get_streak_girlie_comment(substance)
    variations = [
      "This year you were a #{substance} girlie",
      "#{substance} era was strong this year",
      "You were deep in your #{substance} phase",
      "#{substance} had you in a chokehold",
      "#{substance} was your comfort zone",
      "You were living that #{substance} lifestyle",
      "#{substance} was your main character moment",
      "#{substance} really said 'I own you'",
      "#{substance} was your emotional support drug",
      "You were committed to the #{substance} agenda",
      "#{substance} was your ride or die",
      "#{substance} had you on lock",
      "You were in your #{substance} villain era",
      "#{substance} really became your personality",
      "#{substance} was your comfort substance",
      "You were #{substance}'s biggest fan",
      "#{substance} was your go-to therapy",
      "#{substance} really understood you",
      "You and #{substance} had a whole relationship",
      "#{substance} was your security blanket"
    ]
    
    variations.sample
  end

  # Generates monthly breakdown comments with dynamic stats
  def self.get_monthly_breakdown_comment(peak_month_name, peak_count, monthly)
    # Calculate additional stats for comments
    active_months = monthly.keys.length
    
    # Get busiest season
    require_relative 'data_analysis_helper' unless defined?(DataAnalysisHelper)
    seasons = DataAnalysisHelper.get_seasonal_breakdown(monthly)
    busiest_season = seasons.max_by { |_, count| count }&.first
    
    # Build dynamic comments based on stats
    dynamic_comments = []
    
    if peak_month_name
      dynamic_comments << "#{Date.strptime(peak_month_name, '%Y-%m').strftime('%B')} was your peak month (#{peak_count} uses)"
    end
    
    if active_months <= 3
      dynamic_comments << "You kept it concentrated to just #{active_months} months"
    elsif active_months >= 9
      dynamic_comments << "You stayed consistent across #{active_months} months"
    end
    
    if busiest_season
      dynamic_comments << "#{busiest_season} was your season"
    end
    
    dynamic_comments.sample
  end

  # Generates hardest day titles with variations
  def self.get_hardest_day_title(dose_count)
    base_titles = [
      "You really went hard on this day:",
      "You were fuckin' BALLING on this day:",
      "Looks like someone was mfin On one:",
      "You went beast mode:",
      "What was wrong that day?",
      "Someone was having a moment:",
      "This day was unhinged:",
      "You said fuck it and went OFF:",
      "Main character energy was STRONG:",
      "You were in your villain era:",
      "Absolute chaos mode activated:",
      "You were on demon time:",
      "This day was pure mayhem:",
      "You went absolutely feral:",
      "What the hell happened here?"
    ]
    
    # Add dynamic title based on usage count
    if dose_count >= 10
      base_titles << "#{dose_count}-Use Bender, No Surrender. That's dedication"
    elsif dose_count >= 5
      base_titles << "#{dose_count} uses in one day? Someone was feeling themselves"
    end
    
    base_titles.sample
  end

  # Generates top substances comment
  def self.get_top_substances_comment(top_subs)
    return nil if top_subs.empty?
    
    select_random_title([
      "Top 10 Substances:",
      "Your Chemical Hall of Fame:",
      "Most Requested Performers:",
      "The Usual Suspects:",
      "Your Ride or Dies:"
    ])
  end
end
