import { Injectable } from '@nestjs/common';

import { CreateFacilityDto } from './dto/create-facility.dto';
import { UpdateFacilityDto } from './dto/update-facility.dto';
import { Facility } from './entities/facility.entity';
import { FacilitiesRepository } from './facilities.repository';

@Injectable()
export class FacilitiesService {
  constructor(private readonly facilitiesRepository: FacilitiesRepository) {}

  async create(createFacilityDto: CreateFacilityDto): Promise<Facility> {
    return this.facilitiesRepository.create(createFacilityDto);
  }

  async findAll(): Promise<Facility[]> {
    return this.facilitiesRepository.findAll({ relations: ['warehouses'] });
  }

  async findOne(id: string): Promise<Facility | null> {
    return this.facilitiesRepository.findById(id);
  }

  async update(id: string, updateFacilityDto: UpdateFacilityDto): Promise<Facility | null> {
    return this.facilitiesRepository.update(id, updateFacilityDto);
  }

  async remove(id: string): Promise<void> {
    return this.facilitiesRepository.softDelete(id);
  }
}
