import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
import { PartnerRange } from '../models/partner-range.model';

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

  constructor(
    private readonly http: HttpClient
  ) { }

  getPartnerRange(type: string) {
    let url = environment.url + `partner/range?`;
    if ( type !== '') {
      url += `type=${type}`;
    } else {
      url += `type=T`;
    }
    return this.http.get<PartnerRange[]>(url);
  }

  getPartnerRangeById(id: string) {
    const url = environment.url + `partner/range/${id}`;
    return this.http.get<PartnerRange>(url);
  }

  createOrReplace(data: PartnerRange) {
    const url = environment.url + `partner/range/create`;
    return this.http.post<PartnerRange>(url, data);
  }

  DeletePartnerRangeById(id: string) {
    const url = environment.url + `partner/range/delete/${id}`;
    return this.http.delete(url);
  }

}
