import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { FleioApiService } from '../../fleio-api.service';
import { ConfigService } from '@shared/config/config.service';
import { IPredefinedReplyCategoryModel } from '@fleio-api/plugins/tickets/model/predefined-reply-category.model';
import { FleioId } from '@fleio-api/base-model/base-fleio-object.model';
import { Observable } from 'rxjs';
import { IPredefinedReplyModel } from '@fleio-api/plugins/tickets/model/predefined-reply.model';

@Injectable({
  providedIn: 'root'
})
export class PredefinedReplyCategoryApiService extends FleioApiService<IPredefinedReplyCategoryModel> {
  constructor(protected httpClient: HttpClient, protected config: ConfigService) {
    super();
    this.setEndpoint(config.getPanelApiUrl('plugins/tickets/predefined_reply_categories'));
  }

  getPredefinedReplies(categoryId: FleioId, page: number, pageSize=null): Observable<any> {
    const queryParams = {
      page,
    } as any;
    if (pageSize) {
      queryParams.page_size = pageSize;
    }
    return this.objectGetAction(categoryId, 'get_predefined_replies', queryParams);
  }

  getPredefinedReply(categoryId: FleioId, predefinedReplyId: FleioId): Observable<IPredefinedReplyModel> {
    return this.objectGetAction(categoryId, 'get_predefined_reply', {
      predefined_reply_id: predefinedReplyId
    });
  }

  savePredefinedReply(categoryId: FleioId, predefinedReply: IPredefinedReplyModel): Observable<IPredefinedReplyModel> {
    return this.objectPostAction(categoryId, 'save_predefined_reply', predefinedReply);
  }

  deletePredefinedReply(categoryId: FleioId, predefinedReplyID: FleioId): Observable<any> {
    return this.objectPostAction(categoryId, 'delete_predefined_reply', {
      predefined_reply_id: predefinedReplyID
    });
  }
}
