(window["webpackJsonp"] = window["webpackJsonp"] || []).push([["default~app-pages-especificos-ageo-portaria-geracao-geracao-module~app-pages-especificos-agtl-portar~a9aab6cb"],{

/***/ "./src/app/pages/veiculo/check-list/check-list.facade.ts":
/*!***************************************************************!*\
  !*** ./src/app/pages/veiculo/check-list/check-list.facade.ts ***!
  \***************************************************************/
/*! exports provided: CheckListFacade */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CheckListFacade", function() { return CheckListFacade; });
/* harmony import */ var _angular_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @angular/core */ "./node_modules/@angular/core/fesm5/core.js");
/* harmony import */ var app_shared_services_funcoes_boolean_utils_boolean_utils_static_service__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! app/shared/services/funcoes/boolean-utils/boolean-utils.static.service */ "./src/app/shared/services/funcoes/boolean-utils/boolean-utils.static.service.ts");
/* harmony import */ var _shared_services_message_message_service__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./../../../shared/services/message/message.service */ "./src/app/shared/services/message/message.service.ts");
/* harmony import */ var _entrada_veiculo_entrada_veiculo_service__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./../entrada-veiculo/entrada-veiculo.service */ "./src/app/pages/veiculo/entrada-veiculo/entrada-veiculo.service.ts");
/* harmony import */ var _check_list_service__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./check-list.service */ "./src/app/pages/veiculo/check-list/check-list.service.ts");
var __decorate = (undefined && undefined.__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 = (undefined && undefined.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var __importDefault = (undefined && undefined.__importDefault) || function (mod) {
  return (mod && mod.__esModule) ? mod : { "default": mod };
};





var CheckListFacade = /** @class */ (function () {
    function CheckListFacade(service, message, entradaVeiculoService) {
        this.service = service;
        this.message = message;
        this.entradaVeiculoService = entradaVeiculoService;
        this.configs = {
            intCta: false
        };
    }
    CheckListFacade.prototype.aprovarCheckList = function (checkListId, entradaVeiculoId, callback) {
        return __awaiter(this, void 0, void 0, function () {
            var ret1, flagAprovacao, ret2, ret3, error_1;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        _a.trys.push([0, 10, , 11]);
                        return [4 /*yield*/, this.service.checkFlagAprovacao({ checkListId: checkListId }).toPromise()];
                    case 1:
                        ret1 = _a.sent();
                        return [4 /*yield*/, this.processValidationResult(ret1, "titles.consultaPatio", callback)];
                    case 2:
                        if (_a.sent())
                            return [2 /*return*/];
                        flagAprovacao = ret1 && ret1.outFlagAprovacao;
                        if (flagAprovacao && app_shared_services_funcoes_boolean_utils_boolean_utils_static_service__WEBPACK_IMPORTED_MODULE_1__["BooleanUtilsStaticService"].toBoolean(flagAprovacao)) {
                            this.message.warning("titles.consultaPatio", "messages.checkListSendoAprovadoPorOutroUsuario");
                            if (callback)
                                callback({ isValid: false });
                            return [2 /*return*/];
                        }
                        return [4 /*yield*/, this.entradaVeiculoService.checkInspection({ regControle: entradaVeiculoId }).toPromise()];
                    case 3:
                        ret2 = _a.sent();
                        return [4 /*yield*/, this.processValidationResult(ret2, "titles.consultaPatio", callback)];
                    case 4:
                        if (_a.sent())
                            return [2 /*return*/];
                        return [4 /*yield*/, this.entradaVeiculoService.checkPending({ regControle: entradaVeiculoId }).toPromise()];
                    case 5:
                        ret3 = _a.sent();
                        return [4 /*yield*/, this.processValidationResult(ret3, "titles.consultaPatio", callback)];
                    case 6:
                        if (_a.sent())
                            return [2 /*return*/];
                        if (!this.configs.intCta) return [3 /*break*/, 7];
                        if (callback)
                            callback({ validaMotivaMotorista: true });
                        return [3 /*break*/, 9];
                    case 7: return [4 /*yield*/, this.confirmaAprovacao(checkListId, callback)];
                    case 8:
                        _a.sent();
                        _a.label = 9;
                    case 9: return [3 /*break*/, 11];
                    case 10:
                        error_1 = _a.sent();
                        this.processError(error_1, "titles.consultaPatio");
                        if (callback)
                            callback({ isValid: false });
                        return [3 /*break*/, 11];
                    case 11: return [2 /*return*/];
                }
            });
        });
    };
    CheckListFacade.prototype.confirmaAprovacao = function (checkListId, callback) {
        return __awaiter(this, void 0, void 0, function () {
            var ret4, error_2;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        _a.trys.push([0, 4, , 5]);
                        return [4 /*yield*/, this.service.corpWebCheckListConfirma({
                                checkListId: checkListId,
                                aprovado: "A",
                                motivo: "",
                                codSit: 0,
                                regCracha: 0,
                                codPessoa: 0,
                                gravaFoto: "N",
                                bioHK: "",
                                automatico: "N"
                            }).toPromise()];
                    case 1:
                        ret4 = _a.sent();
                        return [4 /*yield*/, this.processValidationResult(ret4, "titles.consultaPatio", callback)];
                    case 2:
                        if (_a.sent())
                            return [2 /*return*/];
                        return [4 /*yield*/, this.service.setFlagAprovacao({ checkListId: checkListId }).toPromise()];
                    case 3:
                        _a.sent();
                        if (callback)
                            callback({ validaMotivaMotorista: false });
                        return [3 /*break*/, 5];
                    case 4:
                        error_2 = _a.sent();
                        this.processError(error_2, "titles.consultaPatio");
                        if (callback)
                            callback({ isValid: false });
                        return [3 /*break*/, 5];
                    case 5: return [2 /*return*/];
                }
            });
        });
    };
    CheckListFacade.prototype.processValidationResult = function (validationResponse, titleKey, callback) {
        return __awaiter(this, void 0, void 0, function () {
            var mensagens;
            var _this = this;
            return __generator(this, function (_a) {
                if (validationResponse && validationResponse.validationResult && !validationResponse.validationResult.isValid) {
                    mensagens = this.message.validationResult(validationResponse.validationResult);
                    mensagens.forEach(function (msg) { return _this.message.warning(titleKey, msg); });
                    if (callback)
                        callback({ isValid: false });
                    return [2 /*return*/, true];
                }
                return [2 /*return*/, false];
            });
        });
    };
    CheckListFacade.prototype.processError = function (error, titleKey) {
        console.error("Erro inesperado:", error);
        this.message.error(titleKey, "messages.unexpectedError");
    };
    CheckListFacade.prototype.suspenderCheckList = function (checkListId, entradaVeiculoId, msg, callback) {
        return __awaiter(this, void 0, void 0, function () {
            var ret5, mensagens, alteracaoNaoPermitida_1, mensagens, ret6;
            var _this = this;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.service.getSituacaoCheckList({
                            acao: "A",
                            regControle: entradaVeiculoId,
                            msg: msg
                        }).toPromise()];
                    case 1:
                        ret5 = _a.sent();
                        if (!ret5.validationResult.isValid) {
                            mensagens = this.message.validationResult(ret5.validationResult);
                            mensagens.forEach(function (m) { return _this.message.warning("titles.consultaPatio", m); });
                            callback({ isValid: false });
                            return [2 /*return*/];
                        }
                        if (!!ret5.msg) {
                            alteracaoNaoPermitida_1 = this.message.getTranslates("messages", "alteracaoNaoPermitida");
                            mensagens = this.message.validationResult(ret5.validationResult);
                            mensagens.forEach(function (m) { return _this.message.warning("titles.consultaPatio", m + " " + alteracaoNaoPermitida_1); });
                            callback({ isValid: false });
                            return [2 /*return*/];
                        }
                        return [4 /*yield*/, this.service.checkSitRegSuspendTruck({ checkListId: checkListId }).toPromise()];
                    case 2:
                        ret6 = _a.sent();
                        if (ret6.outSitReg === "B") {
                            this.message.warning("titles.consultaPatio", "messages.baixadoOperNaoPermitida");
                            callback({ isValid: false });
                            return [2 /*return*/];
                        }
                        else if (ret6.outSitReg === "R") {
                            this.message.warning("titles.consultaPatio", "messages.recusadoOperNaoPermitida");
                            callback({ isValid: false });
                            return [2 /*return*/];
                        }
                        callback({ isValid: true });
                        return [2 /*return*/];
                }
            });
        });
    };
    CheckListFacade.prototype.recusarCheckList = function (checkListId, entradaVeiculoId, msg, callback) {
        return __awaiter(this, void 0, void 0, function () {
            var ret5, mensagens, alteracaoNaoPermitida_2, mensagens, ret6;
            var _this = this;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.service.getSituacaoCheckList({
                            acao: "A",
                            regControle: entradaVeiculoId,
                            msg: msg
                        }).toPromise()];
                    case 1:
                        ret5 = _a.sent();
                        if (!ret5.validationResult.isValid) {
                            mensagens = this.message.validationResult(ret5.validationResult);
                            mensagens.forEach(function (m) { return _this.message.warning("titles.consultaPatio", m); });
                            callback({ isValid: false });
                            return [2 /*return*/];
                        }
                        if (!!ret5.msg) {
                            alteracaoNaoPermitida_2 = this.message.getTranslates("messages", "alteracaoNaoPermitida");
                            mensagens = this.message.validationResult(ret5.validationResult);
                            mensagens.forEach(function (m) { return _this.message.warning("titles.consultaPatio", m + " " + alteracaoNaoPermitida_2); });
                            callback({ isValid: false });
                            return [2 /*return*/];
                        }
                        return [4 /*yield*/, this.service.checkSitRegSuspendTruck({ checkListId: checkListId }).toPromise()];
                    case 2:
                        ret6 = _a.sent();
                        if (ret6.outSitReg === "B") {
                            this.message.warning("titles.consultaPatio", "messages.baixadoOperNaoPermitida");
                            callback({ isValid: false });
                            return [2 /*return*/];
                        }
                        else if (ret6.outSitReg === "R") {
                            this.message.warning("titles.consultaPatio", "messages.recusadoOperNaoPermitida");
                            callback({ isValid: false });
                            return [2 /*return*/];
                        }
                        callback({ isValid: true });
                        return [2 /*return*/];
                }
            });
        });
    };
    CheckListFacade.ctorParameters = function () { return [
        { type: _check_list_service__WEBPACK_IMPORTED_MODULE_4__["CheckListService"] },
        { type: _shared_services_message_message_service__WEBPACK_IMPORTED_MODULE_2__["MessageService"] },
        { type: _entrada_veiculo_entrada_veiculo_service__WEBPACK_IMPORTED_MODULE_3__["EntradaVeiculoService"] }
    ]; };
    CheckListFacade = __decorate([
        Object(_angular_core__WEBPACK_IMPORTED_MODULE_0__["Injectable"])({
            providedIn: "root"
        }),
        __metadata("design:paramtypes", [_check_list_service__WEBPACK_IMPORTED_MODULE_4__["CheckListService"],
            _shared_services_message_message_service__WEBPACK_IMPORTED_MODULE_2__["MessageService"],
            _entrada_veiculo_entrada_veiculo_service__WEBPACK_IMPORTED_MODULE_3__["EntradaVeiculoService"]])
    ], CheckListFacade);
    return CheckListFacade;
}());



/***/ })

}]);
//# sourceMappingURL=default~app-pages-especificos-ageo-portaria-geracao-geracao-module~app-pages-especificos-agtl-portar~a9aab6cb.js.map