class Spirit < ApplicationRecord

    belongs_to :rank
    
    validate :end_date_after_start_date

    def metal
      # Example logic to derive metal from rank
      case rank&.type_name
      when 'Gold'
        'Gold'
      when 'Silver'
        'Silver'
      # Add more cases as needed
      else
        'Unknown'
      end
    end

    private
  
    def end_date_after_start_date
      return if end_date.blank? || start_date.blank?
      if end_date < start_date
        errors.add(:end_date, "must be after the start date")
      end
    end

end
