import { Injectable } from '@angular/core';
import { ConnectorService } from 'src/app/hmg-common/services/connector/connector.service';
import { CheckUserAgreementRequest } from './models/check-user-agreement.request';
import { AuthenticationService } from 'src/app/hmg-common/services/authentication/authentication.service';
import { Observable } from 'rxjs';
import { CheckUserAgreementResponse } from './models/check-user-agreement.response';
import { Request } from 'src/app/hmg-common/services/models/request';
import { GetUserAgreementResponse } from './models/get-user-agreement.response';
import { AddUserAgreementRequest } from './models/add-user-agreement.request';

@Injectable({
    providedIn: 'root'
})
export class AgreementService {

    public static checkAgreementURL = 'Services/Patients.svc/REST/CheckForUsageAgreement';
    public static getAgreementURL = 'Services/Patients.svc/REST/GetUsageAgreementText';
    public static addAgreementURL = 'Services/Patients.svc/REST/AddUsageAgreement';


    constructor(
        public con: ConnectorService,
        public auth: AuthenticationService
    ) {

    }


    public checkUserAgreement(onError: any, errorLabel: string): Observable<CheckUserAgreementResponse> {
        const request = new CheckUserAgreementRequest();
        request.Region = 1;
        this.auth.authenticateRequest(request);
        request.TokenID = '';
        return this.con.post(AgreementService.checkAgreementURL, request, onError, errorLabel);

    }

    public getAgreement(onError: any, errorLabel: string): Observable<GetUserAgreementResponse> {
        const request = new Request();
        this.auth.setPublicFields(request);
        request.TokenID = '';
        return this.con.post(AgreementService.getAgreementURL, request, onError, errorLabel);
    }

    public addUserAgreement(onError: any, errorLabel: string): Observable<GetUserAgreementResponse> {
        const request = new AddUserAgreementRequest();
        request.Region = 1;
        this.auth.authenticateRequest(request);
        request.TokenID = '';
        return this.con.post(AgreementService.addAgreementURL, request, onError, errorLabel);
    }
}

