/**
 * Creative & Artistic Activity Events
 * Activities for creative expression and artistic pursuits (ages 8-100)
 */

import { BaseEvent, EventResult, AnswerOption, EventConfig } from '../base.js';
import { Player } from '../../models/index.js';

/**
 * Learn Painting Event
 */
export class LearnPaintingEvent extends BaseEvent {
  readonly id = 'learnPainting';

  getConfig(): EventConfig {
    return {
      minAge: 8,
      maxAge: 100,
      baseChance: 0.00125,
      triggerType: 'random',
    };
  }

  checkConditions(player: Player): boolean {
    const c = player.c;
    // Check if player already has an art-related activity
    const hasArtActivity = (c.activities ?? []).some(
      (activity: { title?: string }) =>
        activity.title === 'Art Club' || activity.title === 'Painting Class'
    );

    return (
      !player.askedQuestions.has(this.id) &&
      c.ageYears >= 8 &&
      c.ageYears <= 100 &&
      !hasArtActivity
    );
  }

  getQuestion(): string {
    return "You're interested in learning to paint. Take a class?";
  }

  getAnswerOptions(): AnswerOption[] {
    return [
      { option: 'Yes, art classes!', moneyCost: 75 },
      { option: 'Teach myself online' },
      { option: 'Buy supplies and experiment', moneyCost: 30 },
      { option: 'Maybe later' },
    ];
  }

  processAnswer(player: Player, selectedOption: number): EventResult {
    const c = player.c;

    if (selectedOption === 0) {
      if ((c.money ?? 0) < 75) {
        return {
          type: 'messageEvent',
          message: "You don't have enough money for art classes right now.",
        };
      }
      c.money = (c.money ?? 0) - 75;
      c.creativity = Math.min(100, (c.creativity ?? 50) + 20);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 15);

      return {
        type: 'messageEvent',
        message:
          'You enrolled in art classes! The instructor is patient and your skills are improving steadily.',
      };
    } else if (selectedOption === 1) {
      c.creativity = Math.min(100, (c.creativity ?? 50) + 10);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 10);

      return {
        type: 'messageEvent',
        message:
          "You found some great online tutorials and started practicing at home. It's fun learning at your own pace!",
      };
    } else if (selectedOption === 2) {
      if ((c.money ?? 0) < 30) {
        return {
          type: 'messageEvent',
          message: "You don't have enough money for art supplies right now.",
        };
      }
      c.money = (c.money ?? 0) - 30;
      c.creativity = Math.min(100, (c.creativity ?? 50) + 15);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 5);

      return {
        type: 'messageEvent',
        message:
          'You bought paints, brushes, and canvases. Time to experiment and see what happens!',
      };
    } else {
      c.happiness = Math.max(0, (c.happiness ?? 50) - 5);
      return {
        type: 'messageEvent',
        message: 'Maybe another time. You put the idea aside for now.',
      };
    }
  }
}

/**
 * Writing Journal Event
 */
export class WritingJournalEvent extends BaseEvent {
  readonly id = 'writingJournal';

  getConfig(): EventConfig {
    return {
      minAge: 10,
      maxAge: 100,
      baseChance: 0.00167,
      triggerType: 'random',
    };
  }

  checkConditions(player: Player): boolean {
    const c = player.c;
    // Check if player already has a journaling schedule
    const hasJournalingSchedule = (c.schedules ?? []).some(
      (schedule: { title?: string }) => schedule.title === 'Journal writing'
    );

    return (
      !player.askedQuestions.has(this.id) &&
      c.ageYears >= 10 &&
      c.ageYears <= 100 &&
      !hasJournalingSchedule
    );
  }

  getQuestion(): string {
    return 'You want to start writing in a journal. Begin?';
  }

  getAnswerOptions(): AnswerOption[] {
    return [
      { option: 'Yes, write daily' },
      { option: 'Write occasionally' },
      { option: 'No, too personal' },
    ];
  }

  processAnswer(player: Player, selectedOption: number): EventResult {
    const c = player.c;

    if (selectedOption === 0) {
      c.happiness = Math.min(100, (c.happiness ?? 50) + 15);
      c.intelligence = Math.min(100, (c.intelligence ?? 50) + 10);
      c.stress = Math.max(0, (c.stress ?? 0) - 15);

      return {
        type: 'messageEvent',
        message:
          'You commit to writing every day. It becomes a peaceful ritual where you can process your thoughts and feelings.',
      };
    } else if (selectedOption === 1) {
      c.happiness = Math.min(100, (c.happiness ?? 50) + 10);
      c.stress = Math.max(0, (c.stress ?? 0) - 5);

      return {
        type: 'messageEvent',
        message:
          "You write in your journal when the mood strikes. It's nice to have an outlet for your thoughts.",
      };
    } else {
      c.happiness = Math.max(0, (c.happiness ?? 50) - 5);
      return {
        type: 'messageEvent',
        message: "You decide journaling isn't for you. It feels too vulnerable.",
      };
    }
  }
}

/**
 * Learn Photography Event
 */
export class LearnPhotographyEvent extends BaseEvent {
  readonly id = 'learnPhotography';

  getConfig(): EventConfig {
    return {
      minAge: 14,
      maxAge: 100,
      baseChance: 0.001,
      triggerType: 'random',
    };
  }

  checkConditions(player: Player): boolean {
    const c = player.c;
    // Check if player already has a photography activity
    const hasPhotographyActivity = (c.activities ?? []).some(
      (activity: { title?: string }) =>
        activity.title === 'Photography Class' || activity.title === 'Photography Club'
    );

    return (
      !player.askedQuestions.has(this.id) &&
      c.ageYears >= 14 &&
      c.ageYears <= 100 &&
      !hasPhotographyActivity
    );
  }

  getQuestion(): string {
    return "You're interested in photography. Pursue it?";
  }

  getAnswerOptions(): AnswerOption[] {
    return [
      { option: 'Buy a camera and take classes', moneyCost: 500 },
      { option: 'Use phone camera and learn online' },
      { option: 'Just take casual photos' },
      { option: 'Not interested' },
    ];
  }

  processAnswer(player: Player, selectedOption: number): EventResult {
    const c = player.c;

    if (selectedOption === 0) {
      if ((c.money ?? 0) < 500) {
        return {
          type: 'messageEvent',
          message: "You don't have enough money for a camera and photography classes right now.",
        };
      }
      c.money = (c.money ?? 0) - 500;
      c.creativity = Math.min(100, (c.creativity ?? 50) + 25);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 20);

      return {
        type: 'messageEvent',
        message:
          "You invested in a nice camera and signed up for photography classes. Your instructor teaches you composition, lighting, and editing. You're seeing the world through a new lens!",
      };
    } else if (selectedOption === 1) {
      c.creativity = Math.min(100, (c.creativity ?? 50) + 15);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 15);

      return {
        type: 'messageEvent',
        message:
          "You started taking photos with your phone and learning techniques online. Modern phones are amazing cameras, and you're learning fast!",
      };
    } else if (selectedOption === 2) {
      c.creativity = Math.min(100, (c.creativity ?? 50) + 5);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 5);

      return {
        type: 'messageEvent',
        message:
          'You snap photos here and there when something catches your eye. Nothing serious, just for fun.',
      };
    } else {
      c.happiness = Math.max(0, (c.happiness ?? 50) - 5);
      return {
        type: 'messageEvent',
        message: "Photography isn't really your thing. You pass on the opportunity.",
      };
    }
  }
}

/**
 * Theatre Audition Event
 */
export class TheatreAuditionEvent extends BaseEvent {
  readonly id = 'theatreAudition';

  getConfig(): EventConfig {
    return {
      minAge: 10,
      maxAge: 22,
      baseChance: 0.00111,
      triggerType: 'random',
    };
  }

  checkConditions(player: Player): boolean {
    const c = player.c;
    // Check if player already has theater activity
    const hasTheaterActivity = (c.activities ?? []).some(
      (activity: { title?: string }) =>
        activity.title === 'Musical Theater' ||
        activity.title === 'Theater Club' ||
        activity.title === 'Drama Club'
    );

    return (
      !player.askedQuestions.has(this.id) &&
      c.ageYears >= 10 &&
      c.ageYears <= 22 &&
      c.occupation === 'student' &&
      !hasTheaterActivity &&
      c.energy >= 20
    );
  }

  getQuestion(): string {
    return 'Your school/community theater is holding auditions. Try out?';
  }

  getAnswerOptions(): AnswerOption[] {
    return [
      { option: 'Audition for lead role!', energyCost: 20 },
      { option: 'Audition for any role' },
      { option: 'Help with crew/backstage' },
      { option: 'Skip it' },
    ];
  }

  processAnswer(player: Player, selectedOption: number): EventResult {
    const c = player.c;

    if (selectedOption === 0) {
      c.energy = Math.max(0, c.energy - 20);
      c.social = Math.min(100, (c.social ?? 50) + 20);
      c.creativity = Math.min(100, (c.creativity ?? 50) + 15);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 20);

      return {
        type: 'messageEvent',
        message:
          'You went all out for the lead role! You prepared a monologue and gave it your best shot. You got into the theater program!',
      };
    } else if (selectedOption === 1) {
      c.social = Math.min(100, (c.social ?? 50) + 15);
      c.creativity = Math.min(100, (c.creativity ?? 50) + 10);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 15);

      return {
        type: 'messageEvent',
        message:
          "You auditioned and said you'd be happy with any role. The director appreciated your flexibility and enthusiasm! You got into the theater program!",
      };
    } else if (selectedOption === 2) {
      c.social = Math.min(100, (c.social ?? 50) + 10);
      c.creativity = Math.min(100, (c.creativity ?? 50) + 5);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 10);

      return {
        type: 'messageEvent',
        message:
          "You joined the crew working on sets, costumes, or lighting. It's fascinating to see the behind-the-scenes work that makes theater magic!",
      };
    } else {
      c.happiness = Math.max(0, (c.happiness ?? 50) - 10);
      return {
        type: 'messageEvent',
        message: "You decided theater isn't for you and skipped the auditions.",
      };
    }
  }
}

/**
 * Crafting Hobby Event
 */
export class CraftingHobbyEvent extends BaseEvent {
  readonly id = 'craftingHobby';

  private getCraftType(age: number): string {
    if (age < 14) {
      const crafts = ['arts and crafts', 'origami', 'friendship bracelets'];
      return crafts[Math.floor(Math.random() * crafts.length)];
    } else if (age < 30) {
      const crafts = ['knitting', 'painting miniatures', 'jewelry making'];
      return crafts[Math.floor(Math.random() * crafts.length)];
    } else {
      const crafts = ['knitting', 'woodworking', 'pottery', 'quilting'];
      return crafts[Math.floor(Math.random() * crafts.length)];
    }
  }

  getConfig(): EventConfig {
    return {
      minAge: 8,
      maxAge: 100,
      baseChance: 0.00143,
      triggerType: 'random',
    };
  }

  checkConditions(player: Player): boolean {
    const c = player.c;
    // Check if player already has a crafting schedule
    const hasCraftingSchedule = (c.schedules ?? []).some(
      (schedule: { title?: string }) =>
        schedule.title?.includes('Craft') ||
        schedule.title?.includes('Knitting') ||
        schedule.title?.includes('Woodworking')
    );

    return (
      !player.askedQuestions.has(this.id) &&
      c.ageYears >= 8 &&
      c.ageYears <= 100 &&
      !hasCraftingSchedule
    );
  }

  getQuestion(player?: Player): string {
    const craftType = player ? this.getCraftType(player.c.ageYears) : 'crafting';
    return `You want to start a crafting hobby (${craftType}). Begin?`;
  }

  getAnswerOptions(): AnswerOption[] {
    return [
      { option: 'Yes, buy supplies!', moneyCost: 50 },
      { option: 'Start small with basics', moneyCost: 20 },
      { option: 'Not interested' },
    ];
  }

  processAnswer(player: Player, selectedOption: number): EventResult {
    const c = player.c;
    const craftType = this.getCraftType(c.ageYears);

    if (selectedOption === 0) {
      if ((c.money ?? 0) < 50) {
        return {
          type: 'messageEvent',
          message: "You don't have enough money for craft supplies right now.",
        };
      }
      c.money = (c.money ?? 0) - 50;
      c.creativity = Math.min(100, (c.creativity ?? 50) + 15);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 20);
      c.stress = Math.max(0, (c.stress ?? 0) - 10);

      return {
        type: 'messageEvent',
        message: `You went to the craft store and bought everything you needed for ${craftType}! Your first project is already underway. There's something deeply satisfying about making things with your own hands.`,
      };
    } else if (selectedOption === 1) {
      if ((c.money ?? 0) < 20) {
        return {
          type: 'messageEvent',
          message: "You don't have enough money for basic craft supplies right now.",
        };
      }
      c.money = (c.money ?? 0) - 20;
      c.creativity = Math.min(100, (c.creativity ?? 50) + 10);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 15);
      c.stress = Math.max(0, (c.stress ?? 0) - 5);

      return {
        type: 'messageEvent',
        message: `You started with a beginner's kit and basic supplies for ${craftType}. It's a modest beginning, but you're enjoying learning a new skill!`,
      };
    } else {
      c.happiness = Math.max(0, (c.happiness ?? 50) - 5);
      return {
        type: 'messageEvent',
        message: "Crafting doesn't appeal to you right now. You decide to skip it.",
      };
    }
  }
}

/**
 * Digital Art Event
 */
export class DigitalArtEvent extends BaseEvent {
  readonly id = 'digitalArt';

  getConfig(): EventConfig {
    return {
      minAge: 12,
      maxAge: 60,
      baseChance: 0.0002,
      triggerType: 'random',
    };
  }

  checkConditions(player: Player): boolean {
    const c = player.c;
    // Check if player already has a digital art activity
    const hasDigitalArtActivity = (c.activities ?? []).some(
      (activity: { title?: string }) =>
        activity.title === 'Digital Art' || activity.title === 'Digital Illustration'
    );

    return (
      !player.askedQuestions.has(this.id) &&
      c.ageYears >= 12 &&
      c.ageYears <= 60 &&
      !hasDigitalArtActivity
    );
  }

  getQuestion(): string {
    return 'You want to learn digital art and illustration. Start?';
  }

  getAnswerOptions(): AnswerOption[] {
    return [
      { option: 'Buy a drawing tablet!', moneyCost: 200 },
      { option: 'Use free software first' },
      { option: 'Take an online course', moneyCost: 80 },
      { option: 'Not interested' },
    ];
  }

  processAnswer(player: Player, selectedOption: number): EventResult {
    const c = player.c;

    if (selectedOption === 0) {
      c.money = (c.money ?? 0) - 200;
      c.creativity = Math.min(100, (c.creativity ?? 50) + 25);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 20);
      c.intelligence = Math.min(100, (c.intelligence ?? 50) + 5);

      return {
        type: 'messageEvent',
        message:
          'You invested in a professional drawing tablet! The digital canvas opens up endless possibilities. Your art skills are growing fast with the new tools.',
      };
    } else if (selectedOption === 1) {
      c.creativity = Math.min(100, (c.creativity ?? 50) + 12);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 10);

      return {
        type: 'messageEvent',
        message:
          'You started with free digital art software and your mouse/trackpad. It\'s challenging, but you\'re learning the basics of digital art!',
      };
    } else if (selectedOption === 2) {
      c.money = (c.money ?? 0) - 80;
      c.creativity = Math.min(100, (c.creativity ?? 50) + 20);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 15);
      c.intelligence = Math.min(100, (c.intelligence ?? 50) + 8);

      return {
        type: 'messageEvent',
        message:
          'You enrolled in an online digital art course! The structured lessons are helping you master techniques quickly.',
      };
    } else {
      c.happiness = Math.max(0, (c.happiness ?? 50) - 5);
      return {
        type: 'messageEvent',
        message: 'Digital art doesn\'t appeal to you right now.',
      };
    }
  }
}

/**
 * Learn Singing Event
 */
export class LearnSingingEvent extends BaseEvent {
  readonly id = 'learnSinging';

  getConfig(): EventConfig {
    return {
      minAge: 8,
      maxAge: 70,
      baseChance: 0.0002,
      triggerType: 'random',
    };
  }

  checkConditions(player: Player): boolean {
    const c = player.c;
    // Check if player already has a singing activity
    const hasSingingActivity = (c.activities ?? []).some(
      (activity: { title?: string }) =>
        activity.title === 'Singing Lessons' || activity.title === 'Choir'
    );

    return (
      !player.askedQuestions.has(this.id) &&
      c.ageYears >= 8 &&
      c.ageYears <= 70 &&
      !hasSingingActivity
    );
  }

  getQuestion(): string {
    return 'You want to learn to sing better. Start vocal training?';
  }

  getAnswerOptions(): AnswerOption[] {
    return [
      { option: 'Take vocal lessons!', moneyCost: 100 },
      { option: 'Join a choir', moneyCost: 30 },
      { option: 'Practice on my own' },
      { option: 'Not interested' },
    ];
  }

  processAnswer(player: Player, selectedOption: number): EventResult {
    const c = player.c;

    if (selectedOption === 0) {
      c.money = (c.money ?? 0) - 100;
      c.creativity = Math.min(100, (c.creativity ?? 50) + 20);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 20);
      c.stress = Math.max(0, (c.stress ?? 0) - 15);

      return {
        type: 'messageEvent',
        message:
          'You signed up for vocal lessons! Your teacher helps you develop proper technique, expand your range, and gain confidence. Singing becomes a source of joy!',
      };
    } else if (selectedOption === 1) {
      c.money = (c.money ?? 0) - 30;
      c.creativity = Math.min(100, (c.creativity ?? 50) + 15);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 20);
      c.social = Math.min(100, (c.social ?? 50) + 20);
      c.stress = Math.max(0, (c.stress ?? 0) - 10);

      return {
        type: 'messageEvent',
        message:
          'You joined a local choir! Singing with others is magical. You learn harmonies, make friends, and perform for audiences.',
      };
    } else if (selectedOption === 2) {
      c.creativity = Math.min(100, (c.creativity ?? 50) + 8);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 10);

      return {
        type: 'messageEvent',
        message:
          'You practice singing on your own, following online tutorials. It\'s fun to sing along to your favorite songs and improve over time!',
      };
    } else {
      c.happiness = Math.max(0, (c.happiness ?? 50) - 5);
      return {
        type: 'messageEvent',
        message: 'Singing doesn\'t interest you right now.',
      };
    }
  }
}

/**
 * Creative Writing Event
 */
export class CreativeWritingEvent extends BaseEvent {
  readonly id = 'creativeWriting';

  private getWritingType(): string {
    const types = [
      'short stories',
      'poetry',
      'a novel',
      'screenplays',
      'fan fiction',
      'creative nonfiction',
    ];
    return types[Math.floor(Math.random() * types.length)];
  }

  getConfig(): EventConfig {
    return {
      minAge: 12,
      maxAge: 100,
      baseChance: 0.0002,
      triggerType: 'random',
    };
  }

  checkConditions(player: Player): boolean {
    const c = player.c;
    // Check if player already has a writing activity (but not journaling)
    const hasWritingActivity = (c.activities ?? []).some(
      (activity: { title?: string }) =>
        activity.title === 'Creative Writing' || activity.title === 'Writing Workshop'
    );

    return (
      !player.askedQuestions.has(this.id) &&
      c.ageYears >= 12 &&
      c.ageYears <= 100 &&
      !hasWritingActivity
    );
  }

  getQuestion(): string {
    const writingType = this.getWritingType();
    return `You want to try writing ${writingType}. Start?`;
  }

  getAnswerOptions(): AnswerOption[] {
    return [
      { option: 'Join a writing workshop!', moneyCost: 75 },
      { option: 'Start writing on my own' },
      { option: 'Join an online writing community' },
      { option: 'Not interested' },
    ];
  }

  processAnswer(player: Player, selectedOption: number): EventResult {
    const c = player.c;
    const writingType = this.getWritingType();

    if (selectedOption === 0) {
      c.money = (c.money ?? 0) - 75;
      c.creativity = Math.min(100, (c.creativity ?? 50) + 20);
      c.intelligence = Math.min(100, (c.intelligence ?? 50) + 15);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 15);
      c.social = Math.min(100, (c.social ?? 50) + 10);

      return {
        type: 'messageEvent',
        message: `You joined a writing workshop to work on ${writingType}! Getting feedback from fellow writers accelerates your growth. You're developing your unique voice!`,
      };
    } else if (selectedOption === 1) {
      c.creativity = Math.min(100, (c.creativity ?? 50) + 15);
      c.intelligence = Math.min(100, (c.intelligence ?? 50) + 10);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 10);

      return {
        type: 'messageEvent',
        message: `You started writing ${writingType} on your own. The blank page becomes a canvas for your imagination. It's therapeutic and fulfilling!`,
      };
    } else if (selectedOption === 2) {
      c.creativity = Math.min(100, (c.creativity ?? 50) + 12);
      c.intelligence = Math.min(100, (c.intelligence ?? 50) + 8);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 12);
      c.social = Math.min(100, (c.social ?? 50) + 5);

      return {
        type: 'messageEvent',
        message: `You joined an online writing community to share ${writingType}! You get feedback, participate in challenges, and connect with fellow writers.`,
      };
    } else {
      c.happiness = Math.max(0, (c.happiness ?? 50) - 5);
      return {
        type: 'messageEvent',
        message: 'Creative writing isn\'t for you right now.',
      };
    }
  }
}

/**
 * Music Production Event
 */
export class MusicProductionEvent extends BaseEvent {
  readonly id = 'musicProduction';

  getConfig(): EventConfig {
    return {
      minAge: 14,
      maxAge: 50,
      baseChance: 0.0002,
      triggerType: 'random',
    };
  }

  checkConditions(player: Player): boolean {
    const c = player.c;
    return (
      !player.askedQuestions.has(this.id) &&
      c.ageYears >= 14 &&
      c.ageYears <= 50
    );
  }

  getQuestion(): string {
    return 'You want to try making music with digital tools. Start producing?';
  }

  getAnswerOptions(): AnswerOption[] {
    return [
      { option: 'Buy professional software!', moneyCost: 300 },
      { option: 'Use free software first' },
      { option: 'Take an online course', moneyCost: 100 },
      { option: 'Not interested' },
    ];
  }

  processAnswer(player: Player, selectedOption: number): EventResult {
    const c = player.c;

    if (selectedOption === 0) {
      c.money = (c.money ?? 0) - 300;
      c.creativity = Math.min(100, (c.creativity ?? 50) + 25);
      c.intelligence = Math.min(100, (c.intelligence ?? 50) + 10);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 20);

      // Small chance to earn from music
      if (Math.random() < 0.15) {
        const earnings = Math.floor(Math.random() * 100) + 50;
        c.money = (c.money ?? 0) + earnings;
        return {
          type: 'messageEvent',
          message: `You invested in professional music production software! Your beats are catching on, and you even made $${earnings} from licensing a track!`,
        };
      }

      return {
        type: 'messageEvent',
        message:
          'You invested in professional music production software! Creating beats and melodies is incredibly satisfying. You\'re developing your signature sound!',
      };
    } else if (selectedOption === 1) {
      c.creativity = Math.min(100, (c.creativity ?? 50) + 15);
      c.intelligence = Math.min(100, (c.intelligence ?? 50) + 5);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 12);

      return {
        type: 'messageEvent',
        message:
          'You downloaded free music production software and started experimenting. The learning curve is steep, but you\'re making interesting sounds!',
      };
    } else if (selectedOption === 2) {
      c.money = (c.money ?? 0) - 100;
      c.creativity = Math.min(100, (c.creativity ?? 50) + 20);
      c.intelligence = Math.min(100, (c.intelligence ?? 50) + 10);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 15);

      return {
        type: 'messageEvent',
        message:
          'You enrolled in an online music production course! The structured lessons help you understand synthesis, mixing, and arrangement.',
      };
    } else {
      c.happiness = Math.max(0, (c.happiness ?? 50) - 5);
      return {
        type: 'messageEvent',
        message: 'Music production doesn\'t appeal to you right now.',
      };
    }
  }
}

/**
 * Learn Drawing Event
 */
export class LearnDrawingEvent extends BaseEvent {
  readonly id = 'learnDrawing';

  private getDrawingStyle(): string {
    const styles = [
      'sketching',
      'figure drawing',
      'manga/anime style',
      'realistic portraits',
      'cartoon illustration',
      'architectural drawing',
    ];
    return styles[Math.floor(Math.random() * styles.length)];
  }

  getConfig(): EventConfig {
    return {
      minAge: 6,
      maxAge: 100,
      baseChance: 0.0002,
      triggerType: 'random',
    };
  }

  checkConditions(player: Player): boolean {
    const c = player.c;
    // Check if player already has a drawing activity
    const hasDrawingActivity = (c.activities ?? []).some(
      (activity: { title?: string }) =>
        activity.title === 'Drawing Class' || activity.title === 'Sketching'
    );

    return (
      !player.askedQuestions.has(this.id) &&
      c.ageYears >= 6 &&
      c.ageYears <= 100 &&
      !hasDrawingActivity
    );
  }

  getQuestion(): string {
    const style = this.getDrawingStyle();
    return `You want to learn ${style}. Start?`;
  }

  getAnswerOptions(): AnswerOption[] {
    return [
      { option: 'Take drawing classes!', moneyCost: 80 },
      { option: 'Buy supplies and practice' , moneyCost: 40 },
      { option: 'Learn from tutorials' },
      { option: 'Not interested' },
    ];
  }

  processAnswer(player: Player, selectedOption: number): EventResult {
    const c = player.c;
    const style = this.getDrawingStyle();

    if (selectedOption === 0) {
      c.money = (c.money ?? 0) - 80;
      c.creativity = Math.min(100, (c.creativity ?? 50) + 20);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 15);

      return {
        type: 'messageEvent',
        message: `You enrolled in ${style} classes! Your instructor guides you through techniques and fundamentals. Your artwork is improving rapidly!`,
      };
    } else if (selectedOption === 1) {
      c.money = (c.money ?? 0) - 40;
      c.creativity = Math.min(100, (c.creativity ?? 50) + 15);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 10);

      return {
        type: 'messageEvent',
        message: `You bought quality pencils, paper, and supplies for ${style}. Practice makes progress, and you enjoy filling your sketchbook!`,
      };
    } else if (selectedOption === 2) {
      c.creativity = Math.min(100, (c.creativity ?? 50) + 10);
      c.happiness = Math.min(100, (c.happiness ?? 50) + 8);

      return {
        type: 'messageEvent',
        message: `You found online tutorials for ${style}. Drawing along with the lessons, you're surprised how quickly you're improving!`,
      };
    } else {
      c.happiness = Math.max(0, (c.happiness ?? 50) - 5);
      return {
        type: 'messageEvent',
        message: 'Drawing doesn\'t interest you right now.',
      };
    }
  }
}

// Export all creative events
export const creativeEvents = [
  new LearnPaintingEvent(),
  new WritingJournalEvent(),
  new LearnPhotographyEvent(),
  new TheatreAuditionEvent(),
  new CraftingHobbyEvent(),
  new DigitalArtEvent(),
  new LearnSingingEvent(),
  new CreativeWritingEvent(),
  new MusicProductionEvent(),
  new LearnDrawingEvent(),
];
