require "./spec_helper"

describe "IRC bot-core integration" do
  parser = JosieHealth::BotCore::CommandParser.new(";")

  describe "command parsing" do
    it "parses ;k as ketamine dose" do
      cmd = parser.parse("testuser", ";k 50mg")
      cmd.should be_a(JosieHealth::BotCore::RawDoseCommand)
      cmd.as(JosieHealth::BotCore::RawDoseCommand).raw_dose.should eq("50mg ketamine insufflated")
    end

    it "parses ;beer with default count" do
      cmd = parser.parse("testuser", ";beer")
      cmd.should be_a(JosieHealth::BotCore::RawDoseCommand)
      cmd.as(JosieHealth::BotCore::RawDoseCommand).raw_dose.should eq("1 beer oral")
    end

    it "parses ;last with no args as LastDoseCommand" do
      cmd = parser.parse("testuser", ";last")
      cmd.should be_a(JosieHealth::BotCore::LastDoseCommand)
    end

    it "parses ;tz lookup as LookupTimezoneCommand" do
      cmd = parser.parse("testuser", ";tz lookup Denver")
      cmd.should be_a(JosieHealth::BotCore::LookupTimezoneCommand)
    end

    it "parses ;alias del as RemoveAliasCommand" do
      cmd = parser.parse("testuser", ";alias del morning")
      cmd.should be_a(JosieHealth::BotCore::RemoveAliasCommand)
    end

    it "parses ;alias <name> as GetAliasCommand" do
      cmd = parser.parse("testuser", ";alias morning")
      cmd.should be_a(JosieHealth::BotCore::GetAliasCommand)
    end

    it "parses ;lab as LabCommand" do
      cmd = parser.parse("testuser", ";lab creatinine 1.2 mg/dL")
      cmd.should be_a(JosieHealth::BotCore::LabCommand)
    end

    it "parses ;undose as UndoseCommand" do
      cmd = parser.parse("testuser", ";undose")
      cmd.should be_a(JosieHealth::BotCore::UndoseCommand)
    end

    it "parses ;ud as UndoseCommand" do
      cmd = parser.parse("testuser", ";ud")
      cmd.should be_a(JosieHealth::BotCore::UndoseCommand)
    end

    it "parses ;tally as TallyCommand" do
      cmd = parser.parse("testuser", ";tally caffeine")
      cmd.should be_a(JosieHealth::BotCore::TallyCommand)
    end

    it "parses ;doseslogged as DosesLoggedCommand" do
      cmd = parser.parse("testuser", ";doseslogged")
      cmd.should be_a(JosieHealth::BotCore::DosesLoggedCommand)
    end

    it "parses ;gd as GrepDoseCommand" do
      cmd = parser.parse("testuser", ";gd caffeine 5")
      cmd.should be_a(JosieHealth::BotCore::GrepDoseCommand)
    end

    it "parses ;info as SubstanceInfoCommand" do
      cmd = parser.parse("testuser", ";info ketamine")
      cmd.should be_a(JosieHealth::BotCore::SubstanceInfoCommand)
    end

    it "parses ;combo as InteractionCommand" do
      cmd = parser.parse("testuser", ";combo caffeine alcohol")
      cmd.should be_a(JosieHealth::BotCore::InteractionCommand)
    end

    it "parses ;vitals as VitalsCommand" do
      cmd = parser.parse("testuser", ";vitals 72 120/80")
      cmd.should be_a(JosieHealth::BotCore::VitalsCommand)
    end

    it "parses ;pulse as VitalsCommand" do
      cmd = parser.parse("testuser", ";pulse 72")
      cmd.should be_a(JosieHealth::BotCore::VitalsCommand)
    end

    it "parses ;bp as VitalsCommand" do
      cmd = parser.parse("testuser", ";bp 120/80")
      cmd.should be_a(JosieHealth::BotCore::VitalsCommand)
    end
  end

  describe "command aliases added to bot-core" do
    it "parses ;hd as hdose" do
      cmd = parser.parse("testuser", ";hd 1430 50mg caffeine")
      cmd.should be_a(JosieHealth::BotCore::RawDoseCommand)
    end

    it "parses ;rd as redose" do
      cmd = parser.parse("testuser", ";rd")
      cmd.should be_a(JosieHealth::BotCore::RedoseCommand)
    end

    it "parses ;list as listdose" do
      cmd = parser.parse("testuser", ";list")
      cmd.should be_a(JosieHealth::BotCore::ListDoseCommand)
    end

    it "parses ;hha as howhighami" do
      cmd = parser.parse("testuser", ";hha")
      cmd.should be_a(JosieHealth::BotCore::HowHighCommand)
    end

    it "parses ;note as annotate" do
      cmd = parser.parse("testuser", ";note test note")
      cmd.should be_a(JosieHealth::BotCore::AnnotateCommand)
    end

    it "parses ;drugs as listdrugs" do
      cmd = parser.parse("testuser", ";drugs")
      cmd.should be_a(JosieHealth::BotCore::ListDrugsCommand)
    end
  end

  describe "IRC-specific extras" do
    it ";high is handled by IRC layer (not bot-core)" do
      cmd = parser.parse("testuser", ";high")
      cmd.should be_a(JosieHealth::BotCore::UnknownCommand)
    end

    it "extra route shortcuts (insuf, subl) are handled by IRC layer" do
      cmd = parser.parse("testuser", ";insuf 50mg ketamine")
      cmd.should be_a(JosieHealth::BotCore::UnknownCommand)
    end
  end

  describe "route shortcuts shared with bot-core" do
    it "parses ;oral as route dose" do
      cmd = parser.parse("testuser", ";oral 100mg caffeine")
      cmd.should be_a(JosieHealth::BotCore::RawDoseCommand)
      cmd.as(JosieHealth::BotCore::RawDoseCommand).raw_dose.should eq("100mg caffeine oral")
    end

    it "parses ;insufflated as route dose" do
      cmd = parser.parse("testuser", ";insufflated 50mg ketamine")
      cmd.should be_a(JosieHealth::BotCore::RawDoseCommand)
      cmd.as(JosieHealth::BotCore::RawDoseCommand).raw_dose.should eq("50mg ketamine insufflated")
    end

    it "parses ;sniffed as route dose" do
      cmd = parser.parse("testuser", ";sniffed 50mg ketamine")
      cmd.should be_a(JosieHealth::BotCore::RawDoseCommand)
      cmd.as(JosieHealth::BotCore::RawDoseCommand).raw_dose.should eq("50mg ketamine insufflated")
    end
  end

  describe "tier 2 gaps (platform-dependent)" do
    pending "reminder commands (;in, ;every, ;reminders) need IRC callback infrastructure"
    pending "wrapped/vwrapped need media delivery"
    pending "export/import need file delivery"
    pending "apikey needs OAuth flow"
    pending "deleteme needs stateful confirmation"
  end
end
