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

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

  constructor(
    private readonly http: HttpClient
  ) { }

  getPartnerCategory(description: string, type: string) {
    let url = environment.url + `partner/category?`;
    if ( type !== '') {
      url += `type=${type}`;
    } else {
      url += `type=T`;
    }
    if ( description !== '') {
      url += `&description=${description}`;
    }
    return this.http.get<PartnerCategory[]>(url);
  }

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

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

}
