import { SimplePerson, ResourceCost } from './types.js';

export interface AnswerOption extends ResourceCost {
  key: string;
  text: string;
}

export interface QuestionData {
  id: string;
  message: string;
  type: string;
  answers: AnswerOption[];
  characters?: SimplePerson[];
  image?: string;
}

export class Question {
  id: string;
  message: string;
  type: string;
  answers: AnswerOption[];
  characters: SimplePerson[];
  image: string;

  constructor(data: QuestionData) {
    this.id = data.id;
    this.message = data.message;
    this.type = data.type;
    this.answers = data.answers;
    this.characters = data.characters ?? [];
    this.image = data.image ?? '';
  }

  getAnswer(key: string): AnswerOption | undefined {
    return this.answers.find(a => a.key === key);
  }

  toJSON(): QuestionData {
    return {
      id: this.id,
      message: this.message,
      type: this.type,
      answers: this.answers,
      characters: this.characters,
      image: this.image,
    };
  }
}
