// 1. Basisklasse `Person`
class Person {
  constructor(public name: string, public age: number) {}

  getInfo(): string {
    return `Name: ${this.name}, Alter: ${this.age}`;
  }
}

// 2. Abgeleitete Klasse `Employee`
class Employee extends Person {
  constructor(
    name: string,
    age: number,
    public position: string,
    public email: string,
    public phone: string
  ) {
    super(name, age);
  }

  override getInfo(): string {
    return `${super.getInfo()}, Position: ${this.position}`;
  }

  getContactInfo(): string {
    return `Email: ${this.email}, Phone: ${this.phone}`;
  }
}

// 3. Interface `IContact`
interface IContact {
  email: string;
  phone: string;
  getContactInfo(): string;
}

// 4. `Employee` implementiert `IContact`
class EmployeeWithContact extends Employee implements IContact {}

// 5. Type Alias für EmployeeRecord
type EmployeeRecord = {
  id: number;
  data: Employee;
};

// 6. Klasse `Company` mit Index-Signatur
class Company {
  // protected employees: { [id: number]: Employee } = {};
  protected employees: EmployeeRegistry = {};

  addEmployee(employee: Employee): void {
    const id = Object.keys(this.employees).length + 1;
    this.employees[id] = employee;
  }

  getEmployee(id: number): Employee | undefined {
    return this.employees[id];
  }
}

// Bonus: `removeEmployee()` implementieren
class ExtendedCompany extends Company {
  removeEmployee(id: number): void {
    delete this.employees[id];
  }
}

// Alternative mit `Record<number, Employee>`
type EmployeeRegistry = Record<number, Employee>;

const c = new ExtendedCompany();
c.addEmployee(new Employee('Alice', 28, 'admin', 'alice@mail.com', '555'));
c.addEmployee(new Employee('Bob', 42, 'admin', 'bob@mail.com', '666'));

console.log(c.getEmployee(1));
c.removeEmployee(1);
