import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { MutationResult } from 'apollo-angular';
import { Filter } from 'src/app/model/graphql/filter/filter.model';
import { Sort } from 'src/app/model/graphql/filter/sort.model';
import { QueryResult } from 'src/app/model/entities/query-result';
import { DbModel } from 'src/app/model/entities/db-model';

@Injectable({
  providedIn: 'root',
})
export abstract class PageWithHistoryDataService<T> {
  abstract load(
    filter?: Filter[],
    sort?: Sort[],
    skip?: number,
    take?: number
  ): Observable<QueryResult<T>>;

  abstract loadHistory(id: number, options?: object): Observable<DbModel[]>;

  abstract onChange(): Observable<void>;
}

export interface Create<T, C> {
  create(object: C): Observable<T | undefined> | Observable<MutationResult>;
}

export interface Update<T, U> {
  update(object: U): Observable<T | undefined> | Observable<MutationResult>;
}

export interface Delete<T> {
  delete(
    object: T
  ): Observable<T | undefined | boolean> | Observable<MutationResult>;
}

export interface Restore<T> {
  restore(
    object: T
  ): Observable<T | undefined | boolean> | Observable<MutationResult>;
}

export interface LoadHistory<T> {
  loadHistory(
    id: number
  ): Observable<T | undefined | boolean> | Observable<DbModel[] | undefined>;
}
