import 'package:floor/floor.dart';

import '../entity/base_entity.dart';

@Entity(tableName: 'players')
class Player extends BaseEntity {
  @PrimaryKey(autoGenerate: true)
  final int? id;
  final String firstName;
  final String lastName;
  final DateTime birthday;
  final String email;
  final String phoneNumber;
  final String hitColor;

  @ignore
  int totalCount = 0;
  @ignore
  double hitPercentage = 0.0;
  @ignore
  double missPercentage = 0.0;
  @ignore
  int hitCount = 0;
  @ignore
  int missCount = 0;
  @ignore
  int totalPoints = 0;
  @ignore
  List<String> hitSequence = [];
  @ignore
  Map<String, int> padHits = {};
  @ignore
  Map<String, int> padMisses = {};

  Player(this.id, this.firstName, this.lastName, this.birthday, this.email,
      this.phoneNumber, this.hitColor,
      {DateTime? createdAt, DateTime? updatedAt})
      : super(updatedAt ?? DateTime.now(), createdAt: createdAt);

  void resetStats() {
    totalCount = 0;
    hitPercentage = 0.0;
    missPercentage = 0.0;
    hitCount = 0;
    missCount = 0;
    totalPoints = 0;
  }

  void addHit(DateTime currentTime, String padId) {
    hitCount++;
    hitSequence.add('$padId:${currentTime.toString()}');
  }

  void addMiss(String padId) {
    missCount++;
    hitSequence.add('$padId:-1');
  }

  void addPoints() {
    totalPoints += 5;
  }

  void removePoints() {
    totalPoints -= 2;
  }

  String fullName() {
    return '$firstName $lastName';
  }
}
