import { PointOfInterest } from 'src/pointOfInterest/entities/PointOfInterest.entity';
import { Available } from 'src/pointOfInterest/enum/available.enum';
import { Town } from 'src/town/entities/town.entity';
import {
  Column,
  Entity,
  JoinColumn,
  JoinTable,
  ManyToMany,
  ManyToOne,
  OneToMany,
  OneToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { AvailableDate } from './available-date.entity';
import { Category } from 'src/category/entities/category.entity';
import { PlaceTraduction } from './place-traduction.entity';
import { Visited } from 'src/visited/entities/visited.entity';

@Entity()
export class Place {
  @PrimaryGeneratedColumn()
  idPlace: number;

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

  @OneToMany(() => PointOfInterest, (point) => point.idPoint)
  points: PointOfInterest[];

  @OneToMany(() => AvailableDate, (available) => available.place)
  availableDates: AvailableDate[];

  @ManyToMany(() => Category, { eager: true })
  @JoinTable()
  categories: Category[];

  @OneToMany(() => PlaceTraduction, (placeTraduction) => placeTraduction.idPlace)
  placeTraduction: PlaceTraduction[];

  @OneToOne(() => Visited, (visited) => visited.place)
  visited: Visited[];
  @Column()
  available: Available;

  @Column()
  name: string;

  @Column()
  imageName: string;

  @Column({ nullable: false, type: 'decimal', precision: 20, scale: 4 })
  latitude;

  @Column({ nullable: false, type: 'decimal', precision: 20, scale: 4 })
  longitude;

  @Column({ nullable: false })
  address: string;

  @Column({ nullable: false })
  openAt: number;

  @Column({ nullable: false })
  closeAt: number;
}
