import {
  Column,
  CreateDateColumn,
  Entity,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { LocationDefinition } from '../../world/entities/location-definition.entity';

@Entity({ name: 'characters' })
export class Character {
  @PrimaryGeneratedColumn('uuid', { name: 'id' })
  id!: string;

  @Column({ name: 'name', type: 'varchar', length: 150 })
  name!: string;

  @Column({ name: 'level', type: 'integer' })
  level!: number;

  @Column({ name: 'experience', type: 'integer' })
  experience!: number;

  @Column({ name: 'base_hp', type: 'integer' })
  baseHp!: number;

  @Column({ name: 'base_attack', type: 'integer' })
  baseAttack!: number;

  @Column({ name: 'current_hp', type: 'integer' })
  currentHp!: number;

  @Column({ name: 'current_location_id', type: 'uuid' })
  currentLocationId!: string;

  @CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
  createdAt!: Date;

  @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
  updatedAt!: Date;

  @ManyToOne(() => LocationDefinition, (location) => location.characters, {
    onDelete: 'RESTRICT',
  })
  @JoinColumn({ name: 'current_location_id' })
  currentLocation!: LocationDefinition;
}
