import { Injectable } from "@angular/core";
import { Timestamp } from "../../interfaces/timestamp";
import { ApiService } from "../../services/api.service";
import { HttpClient } from "@angular/common/http";
import { HelpersService } from "../../services/helpers.service";
import { User } from "../manage/user.service";
import {
  Rating,
  Schedule,
  Segmens,
  StatusReport,
  Survey,
} from "../../interfaces/master";
import { BehaviorSubject, Observable } from "rxjs";
import { ObjectResponse } from "../../interfaces/api-object-response";

export interface Laporan extends Timestamp {
  user_level: any;
  user_type: any;
  id: string;
  user_id: string;
  status_id: string;
  note: string;
  no_ticket: string;
  assign_survey_to: string;
  survey_status: boolean;
  survey?: Survey;
  status_report: StatusReport;
  user: User;
  survey_end_date: string;
  survey_start_date: string;
  schedule: Schedule;
  segmens: Segmens[];
  rating?: Rating;
}

@Injectable({
  providedIn: "root",
})
export class LaporanService extends ApiService<Laporan> {
  private reportDetailsSubject = new BehaviorSubject<Laporan | null>(null);

  constructor(
    public override http: HttpClient,
    public override helpers: HelpersService
  ) {
    super(http, helpers);
    this.endpoint = "report-list";
  }

  getData(
    id: string | number,
    query?: any
  ): Observable<ObjectResponse<Laporan>> {
    const url = this.urlWithId(id);
    const params = query ? this.helpers.generateParams(query) : {};
    return this.http.get<ObjectResponse<Laporan>>(url, { params });
  }
}
