import { autoinject } from "aurelia-framework";
import { HttpClient } from 'aurelia-fetch-client';
import { Config } from '../config';
import * as breeze from 'breeze-client';

@autoinject
export class ChatHistoryUtils {
    constructor(private httpClient: HttpClient, private config: Config) { }

    public viewHistory: boolean = false;
    public viewChat: boolean = false;

    public async canViewHistory(entity: breeze.Entity) {
        let result = await this.httpClient.fetch(this.config.globalConfig.remoteServiceName + "/api/metadata/entityIsAuditable?entityTypeName=" + entity.entityType.shortName);
        if (result.ok) {
            this.viewHistory = await result.json();
        }
        return this.viewHistory;
    }

    public async canViewChat(entity: breeze.Entity) {
        let result = await this.httpClient.fetch(this.config.globalConfig.remoteServiceName + "/api/metadata/entityIsChatable?entityTypeName=" + entity.entityType.shortName);
        if (result.ok) {
            this.viewChat = await result.json();
        }
        return this.viewChat;
    }
}