import { Injectable } from '@angular/core';
import { RegisterRequest } from '../models/register-request.model';
import { BehaviorSubject, Observable } from 'rxjs';
import { Plan } from '../models/plan.model';
import { HitAWodService } from './hit-a-wod.service';
import { SubscriptionService } from './subscription.service';

@Injectable({
  providedIn: 'root'
})
export class RegisterService {

  private stepSubject:BehaviorSubject<number> = new BehaviorSubject(1);
  public currentStep:Observable<number> = this.stepSubject.asObservable();
  private plans:Plan[];

  request:RegisterRequest = new RegisterRequest();

  constructor(private api:HitAWodService,
              private subscriptionService:SubscriptionService) {
    this.subscriptionService.removeSubscription();
    this.fetchPlans();
  }

  public setStep(step:number) {
    if(step!=null && step!=undefined) {
      this.stepSubject.next(step);
    }
  }

  public getPlans() {
    return this.plans;
  }

  private fetchPlans() {
    this.api.getAllPlans().subscribe(
      data => {
        this.plans = data.data;
      },
      error => {

      }
    );
  }
}
