import { Component } from '@angular/core';
import { DataService } from 'src/services/data/data.service';
import { Router } from '@angular/router';

@Component({
  selector: 'app-character-creator',
  templateUrl: './character-creator.component.html',
  styleUrls: ['./character-creator.component.scss'],
})
export class CharacterCreatorComponent {
  public constructor(public dataService: DataService, private Router: Router) {}

  public characterName: string = '';

  public async createCharacter(): Promise<void> {
    // Creates a new entry in the character collection
    this.dataService.addData('characters', { name: this.characterName });
    // TODO: Animation, dass der Character erstellt wurde
    await this.createNewCharacterInDatabase();
    // Die Funktion muss ertstmal durchlaufen, bevor der Character ausgewählt werden kann
    this.dataService.selectCharacter(this.characterName);
  }

  public async createNewCharacterInDatabase(): Promise<void> {
    // TODO: Für alle Daten einen eigenen Key/Value Eintrag anlegen addData(collection: string, data: any, key?: string): void
    return Promise.all([
      // Character Data
      this.dataService.addData(
        this.characterName,
        {
          name: this.characterName,
          class: '',
          race: '',
          level: '',
          subclass: '',
          proficiency: '',
          background: '',
          experience: '',
          inspiration: '',
          proficiencyBonus: '',
        },
        'characterData'
      ),

      // Character Attributes
      this.dataService.addData(
        this.characterName,
        {
          strength: ['', false],
          dexterity: ['', false],
          constitution: ['', false],
          intelligence: ['', false],
          wisdom: ['', false],
          charisma: ['', false],
        },
        'attribute'
      ),

      // Character Skills
      this.dataService.addData(
        this.characterName,
        {
          acrobatics: ['', false],
          animalHandling: ['', false],
          arcana: ['', false],
          athletics: ['', false],
          deception: ['', false],
          history: ['', false],
          insight: ['', false],
          intimidation: ['', false],
          investigation: ['', false],
          medicine: ['', false],
          nature: ['', false],
          perception: ['', false],
          performance: ['', false],
          persuasion: ['', false],
          religion: ['', false],
          sleightOfHand: ['', false],
          stealth: ['', false],
          survival: ['', false],
        },
        'skills'
      ),
      // Character Combat Stats
      this.dataService.addData(
        this.characterName,
        {
          armorClass: '',
          initiative: '',
          speed: '',
          hitPointMaximum: '',
          currentHitPoints: '',
          temporaryHitPoints: '',
          hitDice: '',
          deathSaveSuccesses: '',
          deathSaveFailures: '',
        },
        'combatStats'
      ),
      // Character Appearance
      this.dataService.addData(
        this.characterName,
        {
          age: '',
          height: '',
          weight: '',
          eyes: '',
          skin: '',
          hair: '',
        },
        'appearance'
      ),
      // Character Personality
      this.dataService.addData(
        this.characterName,
        {
          personalityTraits: '',
          ideals: '',
          bonds: '',
          flaws: '',
        },
        'personality'
      ),
      // Character Weapons
      this.dataService.addData(
        this.characterName,
        {
          name: '',
          attackBonus: '',
          damage: '',
          type: '',
          range: '',
          description: '',
        },
        'weapons'
      ),

      // Inventory

      // Weapons

      // Spells

      // Notes

      // Maps

      // NPCs

      // Quests
    ]).then(() => {});
  }
}
