import {
  Column,
  CreateDateColumn,
  Entity,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { Character } from '../../characters/entities/character.entity';
import { LocationDefinition } from '../../world/entities/location-definition.entity';
import { TravelStatus } from '../travel-status.enum';

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

  @Column({ name: 'character_id', type: 'uuid' })
  characterId!: string;

  @Column({ name: 'origin_location_id', type: 'uuid' })
  originLocationId!: string;

  @Column({ name: 'target_location_id', type: 'uuid' })
  targetLocationId!: string;

  @Column({ name: 'started_at', type: 'timestamptz' })
  startedAt!: Date;

  @Column({ name: 'arrives_at', type: 'timestamptz' })
  arrivesAt!: Date;

  @Column({
    name: 'status',
    type: 'enum',
    enum: TravelStatus,
    enumName: 'travel_status_enum',
  })
  status!: TravelStatus;

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

  @ManyToOne(() => Character, { onDelete: 'RESTRICT' })
  @JoinColumn({ name: 'character_id' })
  character!: Character;

  @ManyToOne(() => LocationDefinition, { onDelete: 'RESTRICT' })
  @JoinColumn({ name: 'origin_location_id' })
  originLocation!: LocationDefinition;

  @ManyToOne(() => LocationDefinition, { onDelete: 'RESTRICT' })
  @JoinColumn({ name: 'target_location_id' })
  targetLocation!: LocationDefinition;
}
