import { IsNotEmpty } from "class-validator";
import { ChildEntity, Index, ManyToOne } from "typeorm";
import { ResponseRunnerTeam } from '../responses/ResponseRunnerTeam';
import { RunnerGroup } from "./RunnerGroup";
import type { RunnerOrganization } from "./RunnerOrganization";

/**
 * Defines the RunnerTeam entity.
 * This usually is a school class or department in a company.
 */
@ChildEntity()
@Index(['parentGroup'])
export class RunnerTeam extends RunnerGroup {

  /**
   * The team's parent group.
   * Every team has to be part of a runnerOrganization - this get's checked on creation and update.
   */
  @IsNotEmpty()
  @ManyToOne(() => require("./RunnerOrganization").RunnerOrganization, (org: RunnerOrganization) => org.teams, { nullable: true })
  parentGroup?: RunnerOrganization;

  /**
   * Turns this entity into it's response class.
   */
  public toResponse(): ResponseRunnerTeam {
    return new ResponseRunnerTeam(this);
  }
}