import { Town } from 'src/town/entities/town.entity';
import { TravelPlace } from 'src/travel-place/entities/travel-place.entity';
import { User } from 'src/user/entities/user.entity';
import { PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, Entity, OneToMany } from 'typeorm';
export enum RouteStatus {
  PENDING = 'pending',
  ACCEPTED = 'accepted',
  REJECTED = 'rejected',
}

@Entity()
export class Route {
  @PrimaryGeneratedColumn()
  idRoute: number;

  @JoinColumn({ name: 'user' })
  @ManyToOne(() => User, (user) => user.email, { nullable: false })
  user: User;

  @JoinColumn({ name: 'town' })
  @ManyToOne(() => Town, (town) => town.townId, { nullable: false, eager: true })
  town: Town;

  @OneToMany(() => TravelPlace, (travelPlace) => travelPlace.route, { eager: true })
  travelPlace: TravelPlace[];

  @Column({ nullable: false })
  startDate: Date;
  @Column({ nullable: false })
  endDate: Date;

  @Column({ nullable: false, default: RouteStatus.PENDING })
  status: RouteStatus;
}
