import { BaseRepository } from "@edr/api-common";
import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { Repository } from "typeorm";

import { GpsDevice } from "./entities/gps-device.entity";
import { GpsPosition } from "./entities/gps-position.entity";

@Injectable()
export class GpsDeviceRepository extends BaseRepository<GpsDevice> {
  constructor(@InjectRepository(GpsDevice) repository: Repository<GpsDevice>) {
    super(repository);
  }

  findByImei(imei: string): Promise<GpsDevice | null> {
    return this.repository.findOne({ where: { imei } });
  }
}

@Injectable()
export class GpsPositionRepository extends BaseRepository<GpsPosition> {
  constructor(@InjectRepository(GpsPosition) repository: Repository<GpsPosition>) {
    super(repository);
  }
}
