import { Injectable } from '@angular/core';
import { Observable, defer } from 'rxjs';

import { DatabaseService } from './database.service';
import { LaunchState } from '../model';

@Injectable({
  providedIn: 'root'
})
export class LaunchService {
  public constructor(private readonly databaseService: DatabaseService) {}

  public save(launchState: LaunchState): Observable<number> {
    return defer(async () => {
      return await this.databaseService.launches.add(launchState);
    });
  }
}
