/**
 * School Life Events
 * Daily school events, interactions, and situations (ages 6-18)
 */

import { Player } from '../../models/Player';
import { createMessageEvent, createQuestionEvent, checkProbability, createAnswerOption, type EventResult } from '../base';

export function likeSchool(player: Player, _type: 'message' | 'question' = 'message'): EventResult {
  const fname = 'likeSchool';
  const check = !player.askedQuestions.has(fname) &&
    player.character.occupation === 'student' &&
    player.character.ageYears >= 4 &&
    player.character.ageYears < 8 &&
    checkProbability(1000);

  if (check) {
    player.askedQuestions.add(fname);
  }

  return createQuestionEvent(fname, "You have started Kindergarten, do you like it?", player, check, {
    answerOptions: ['Yes', 'No']
  });
}

export function dropBooks(player: Player, _type: 'message' | 'question' = 'message'): EventResult {
  const fname = 'dropBooks';
  const check = !player.askedQuestions.has(fname) &&
    player.character.location.includes('school') &&
    checkProbability(1000);

  if (check) {
    player.askedQuestions.add(fname);
  }

  return createQuestionEvent(
    fname,
    "You're walking down a busy hall at school and see someone drop their books.",
    player,
    check,
    {
      answerOptions: [
        createAnswerOption('Stop and help them pick up their books', '', 5, 0, 0),
        createAnswerOption('Keep walking'),
        createAnswerOption('Stop and laugh - what a loser!'),
        createAnswerOption('Grab a few books and offer to walk them to class', '', 0, 5, 0)
      ]
    }
  );
}

export function fieldTrip(player: Player, _type: 'message' | 'question' = 'message'): EventResult {
  const fname = 'fieldTrip';
  const check = !player.askedQuestions.has(fname) &&
    player.character.ageYears >= 8 &&
    player.character.ageYears <= 12 &&
    checkProbability(100);

  if (check) {
    player.askedQuestions.add(fname);
  }

  return createQuestionEvent(
    fname,
    "Your school has handed you a form for the next field trip - it looks like you're able to vote for where to go! What looks best?",
    player,
    check,
    {
      answerOptions: [
        createAnswerOption('Visit the local zoo', '', 0, 0, 20),
        createAnswerOption('Explore the science museum', '', 0, 0, 15),
        createAnswerOption('Take a trip to a historical landmark', '', 0, 0, 10)
      ]
    }
  );
}

export function vendingMachine(player: Player, _type: 'message' | 'question' = 'message'): EventResult {
  const fname = 'vendingMachine';
  const check = !player.askedQuestions.has(fname) &&
    player.character.location.includes('school') &&
    checkProbability(1000);

  if (check) {
    player.askedQuestions.add(fname);
  }

  return createQuestionEvent(
    fname,
    "You walk past someone standing next to a vending machine at school. As you pass, they yell 'Hey - this machine isn't accepting my dollar, can you help out?'",
    player,
    check,
    {
      answerOptions: [
        createAnswerOption('Point to your headphones and shake your head'),
        createAnswerOption('Give them one of your dollar bills to try', '', 0, 0, 1),
        createAnswerOption('You only have a 5 dollar bill, but hand it over anyways', '', 0, 0, 5),
        createAnswerOption('Walk over and hit the vending machine', '', 0, 10, 0)
      ]
    }
  );
}

export function schoolAssembly(player: Player, _type: 'message' | 'question' = 'message'): EventResult {
  const fname = 'schoolAssembly';
  const check = !player.askedQuestions.has(fname) &&
    player.character.location.includes('school') &&
    checkProbability(1000);

  if (check) {
    player.askedQuestions.add(fname);
  }

  return createQuestionEvent(
    fname,
    "All students are called for an impromptu assembly. Once you take your seat, the speaker asks for a volunteer.",
    player,
    check,
    {
      answerOptions: ['Raise your hand', "Shrink smaller into your seat, hoping he doesn't see you"]
    }
  );
}

export function schoolFight(player: Player, _type: 'message' | 'question' = 'message'): EventResult {
  const fname = 'schoolFight';
  const check = !player.askedQuestions.has(fname) &&
    player.character.location.includes('school') &&
    player.character.ageYears >= 14 &&
    player.character.ageYears <= 18 &&
    checkProbability(100);

  if (check) {
    player.askedQuestions.add(fname);
  }

  return createQuestionEvent(
    fname,
    "Tensions are high, and a fight is about to break out at school. What will you do?",
    player,
    check,
    {
      answerOptions: [
        createAnswerOption('Intervene and try to break up the fight', '', 15, 0, 0),
        createAnswerOption('Stay out of it and find a teacher to handle the situation', '', 5, 0, 0),
        createAnswerOption('Join in and fight alongside your friends', '', 0, 10, 0)
      ]
    }
  );
}

export function schoolLunch(player: Player, _type: 'message' | 'question' = 'message'): EventResult {
  const fname = 'schoolLunch';
  const check = !player.askedQuestions.has(fname) &&
    player.hourOfDay === 12 &&
    player.character.location.includes('school') &&
    checkProbability(100);

  if (check) {
    player.askedQuestions.add(fname);
  }

  return createQuestionEvent(
    fname,
    "Your stomach growls - when's lunch? Thankfully, the bell rings and you make your way to the cafeteria. What are you eating today?",
    player,
    check,
    {
      answerOptions: [
        createAnswerOption('Grab a slice of pizza and a soda', '', 0, 0, 10),
        createAnswerOption('Choose a healthy salad and a bottle of water', '', 0, 10, 0),
        createAnswerOption('Go to your locker and grab your packed lunch from home', '', 5, 0, 0),
        createAnswerOption("Grab someone else's lunch")
      ]
    }
  );
}

export function forgotCombo(player: Player, _type: 'message' | 'question' = 'message'): EventResult {
  const fname = 'forgotCombo';
  const check = !player.askedQuestions.has(fname) &&
    player.character.location.includes('school') &&
    player.character.ageYears >= 11 &&
    player.character.ageYears <= 15 &&
    checkProbability(100);

  if (check) {
    player.askedQuestions.add(fname);
  }

  return createQuestionEvent(
    fname,
    "You walk over to your locker and enter your combo. 25-44-... what was the last number? You start to panic, did you forget your combination?",
    player,
    check,
    {
      answerOptions: [
        createAnswerOption('Ask a friend if they remember your combination', '', 5, 0, 0),
        createAnswerOption('Head to the school office to get some help', '', 10, 0, 0),
        createAnswerOption('Brute force your combination', '', 0, 10, 0),
        createAnswerOption('Start kicking your locker', '', 5, 0, 0)
      ]
    }
  );
}

export function lateToSchool(player: Player, _type: 'message' | 'question' = 'message'): EventResult {
  const fname = 'latetoSchool';
  const check = !player.askedQuestions.has(fname) &&
    player.character.location.includes('home') &&
    checkProbability(1000);

  if (check) {
    player.askedQuestions.add(fname);
  }

  return createQuestionEvent(
    fname,
    "You woke up late and now you're running behind for school. What will you do?",
    player,
    check,
    {
      answerOptions: [
        createAnswerOption('Arrive late and get a tardy'),
        createAnswerOption('Hurry to school as fast as you can', '', 20, 0, 0),
        createAnswerOption('Skip school for the day', '', 0, 10, 0)
      ]
    }
  );
}

export function tiredInClass(player: Player, _type: 'message' | 'question' = 'message'): EventResult {
  const fname = 'tiredinClass';
  const check = !player.askedQuestions.has(fname) &&
    player.character.location.includes('school') &&
    checkProbability(1000);

  if (check) {
    player.askedQuestions.add(fname);
  }

  return createQuestionEvent(
    fname,
    "You had a late night last night and now you're struggling to stay awake in class. What will you do?",
    player,
    check,
    {
      answerOptions: [
        createAnswerOption('Try as hard as you can to stay awake and pay attention', '', 10, 0, 0),
        createAnswerOption('Ask the teacher if you can head to the bathroom', '', 0, 5, 0),
        createAnswerOption("Take a quick nap and hope the teacher doesn't notice", '', 5, 0, 0)
      ]
    }
  );
}
