var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Injectable } from '@angular/core';
import { throwError } from 'rxjs';
import { AbstractAppConfig } from '../../../app.config';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { HttpErrorService } from '../http';
import { catchError, map } from 'rxjs/operators';
var WorkbasketInputFilterService = /** @class */ (function () {
    function WorkbasketInputFilterService(httpClient, appConfig, errorService) {
        this.httpClient = httpClient;
        this.appConfig = appConfig;
        this.errorService = errorService;
    }
    WorkbasketInputFilterService_1 = WorkbasketInputFilterService;
    WorkbasketInputFilterService.prototype.getWorkbasketInputs = function (jurisdictionId, caseTypeId) {
        var _this = this;
        var url = this.getWorkbasketInputUrl(caseTypeId);
        var headers = new HttpHeaders({
            'Accept': [
                WorkbasketInputFilterService_1.V2_MEDIATYPE_WORKBASKET_INPUT_DETAILS,
                WorkbasketInputFilterService_1.QC_V2_MEDIATYPE_WORKBASKET_INPUT_DETAILS
            ],
        });
        this.currentJurisdiction = jurisdictionId;
        this.currentCaseType = caseTypeId;
        return this.httpClient
            .get(url, { headers: headers })
            .pipe(map(function (response) {
            var workbasketInputs = response.workbasketInputs;
            if (_this.isDataValid(jurisdictionId, caseTypeId)) {
                workbasketInputs.forEach(function (item) {
                    item.field.label = item.label;
                });
            }
            else {
                throw new Error('Response expired');
            }
            return workbasketInputs;
        }), catchError(function (error) {
            _this.errorService.setError(error);
            return throwError(error);
        }));
    };
    WorkbasketInputFilterService.prototype.getWorkbasketInputUrl = function (caseTypeId) {
        return this.appConfig.getCaseDataUrl() + "/internal/case-types/" + caseTypeId + "/work-basket-inputs";
    };
    WorkbasketInputFilterService.prototype.isDataValid = function (jurisdictionId, caseTypeId) {
        return this.currentJurisdiction === jurisdictionId && this.currentCaseType === caseTypeId;
    };
    var WorkbasketInputFilterService_1;
    WorkbasketInputFilterService.V2_MEDIATYPE_WORKBASKET_INPUT_DETAILS = 'application/vnd.uk.gov.hmcts.ccd-data-store-api.ui-workbasket-input-details.v2+json;charset=UTF-8';
    WorkbasketInputFilterService.QC_V2_MEDIATYPE_WORKBASKET_INPUT_DETAILS = 'application/vnd.app.quickcase.store.data.api.ui-workbasket-input-details.v2+json;charset=UTF-8';
    WorkbasketInputFilterService = WorkbasketInputFilterService_1 = __decorate([
        Injectable(),
        __metadata("design:paramtypes", [HttpClient, AbstractAppConfig, HttpErrorService])
    ], WorkbasketInputFilterService);
    return WorkbasketInputFilterService;
}());
export { WorkbasketInputFilterService };
//# sourceMappingURL=workbasket-input-filter.service.js.map