import { Injectable, NotFoundException } from '@nestjs/common';
import { TripSettingsRepository } from './trip-settings.repository';
import type { TripSettings, UpdateTripSettingsDto } from './trip.types';

@Injectable()
export class TripSettingsService {
  constructor(private readonly repository: TripSettingsRepository) {}

  async getSettings(tripId: string): Promise<TripSettings> {
    const settings = await this.repository.findByTripId(tripId);
    if (!settings) throw new NotFoundException('Trip settings not found');
    return settings;
  }

  replaceSettings(
    tripId: string,
    dto: UpdateTripSettingsDto,
  ): Promise<TripSettings> {
    return this.repository.replace(tripId, dto);
  }
}
