import { Injectable } from '@angular/core';

import { AuthApi } from './apis/auth';
import { BasicApi } from './apis/basic';
import { KnowledgeApi } from './apis/knowledge';
import { UserApi } from './apis/user';
import { HttpService } from './http.service';

@Injectable({ providedIn: 'root' })
export class ApiService {
  constructor(
    public readonly http: HttpService,
    public readonly basic: BasicApi,
    public readonly auth: AuthApi,
    public readonly user: UserApi,
    public readonly knowledge: KnowledgeApi
  ) {}

  getAllUrls(): string[] {
    const ret: string[] = [];
    for (const key in this) {
      if (Object.prototype.hasOwnProperty.call(this, key)) {
        const element = this[key];
        const proto = Object.getPrototypeOf(element);
        if (proto.urls) {
          proto.urls.forEach((url: string) => {
            ret.push(url);
          });
        }
      }
    }
    return ret;
  }

  getPostParams(): any {
    return {
      current: 0,
      page: 10,
      sequence: {
        prop: 'id',
        order: 'ascending',
      },
    };
  }
}
