import { Injectable } from '@nestjs/common';
import { CreateTravelPlaceDto } from './dto/create-travel-place.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { TravelPlace } from './entities/travel-place.entity';
import { Repository } from 'typeorm';
import { Place } from 'src/place/entities/place.entity';
import { Route } from 'src/route/entities/route.entity';

@Injectable()
export class TravelPlaceService {
  constructor(
    @InjectRepository(TravelPlace) private travelPlaceRepository: Repository<TravelPlace>,
    @InjectRepository(Place) private placeRepository: Repository<Place>,
    @InjectRepository(Route) private routeRepository: Repository<Route>,
  ) {}

  async create(createTravelPlaceDto: CreateTravelPlaceDto) {
    const route = await this.routeRepository.findOneBy({ idRoute: createTravelPlaceDto.idRoute });
    const place = await this.placeRepository.findOneBy({ idPlace: createTravelPlaceDto.idPlace });
    await this.travelPlaceRepository.save({
      route,
      place,
      startDate: createTravelPlaceDto.startDate,
      endDate: createTravelPlaceDto.endDate,
      done: createTravelPlaceDto.done,
    });
  }

  // findAll() {
  //   return `This action returns all travelPlace`;
  // }

  // findOne(id: number) {
  //   return `This action returns a #${id} travelPlace`;
  // }

  // update(id: number, updateTravelPlaceDto: UpdateTravelPlaceDto) {
  //   return `This action updates a #${id} travelPlace`;
  // }

  // remove(id: number) {
  //   return `This action removes a #${id} travelPlace`;
  // }
}
