"use strict";
var __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.taskDefaultFields = exports.Routes = exports.baseRoute = exports.TaskRealTimeEvents = exports.answersExtractor = exports.quotesExtractor = exports.formExtractor = exports.taskIdsExtractor = exports.scanCodeExtractor = exports.locationExtractor = exports.childTasksExtractor = exports.tasksExtractor = exports.successExtractor = exports.taskExtractor = exports.defaultExtractor = exports.noteTypes = exports.taskToGroupMapper = exports.groupFilter = exports.TaskGroupTypes = exports.GROUP_VALUES = void 0;
var TaskHelpers_1 = require("./TaskHelpers");
var GROUP_VALUES;
(function (GROUP_VALUES) {
    GROUP_VALUES[GROUP_VALUES["General"] = 0] = "General";
    GROUP_VALUES[GROUP_VALUES["Open"] = 1] = "Open";
    GROUP_VALUES[GROUP_VALUES["Planning"] = 2] = "Planning";
    GROUP_VALUES[GROUP_VALUES["Closed"] = 3] = "Closed";
    GROUP_VALUES[GROUP_VALUES["Invalid"] = 4] = "Invalid";
    GROUP_VALUES[GROUP_VALUES["Unacknowledged"] = 5] = "Unacknowledged";
    GROUP_VALUES[GROUP_VALUES["Followers"] = 6] = "Followers";
})(GROUP_VALUES = exports.GROUP_VALUES || (exports.GROUP_VALUES = {}));
var TaskGroupTypes;
(function (TaskGroupTypes) {
    TaskGroupTypes["Main"] = "main";
    TaskGroupTypes["Followers"] = "followers";
})(TaskGroupTypes = exports.TaskGroupTypes || (exports.TaskGroupTypes = {}));
exports.groupFilter = new Map([
    [GROUP_VALUES.Open, TaskHelpers_1.TaskHelpers.isInOpenState],
    [GROUP_VALUES.Planning, TaskHelpers_1.TaskHelpers.isInPlanningState],
    [GROUP_VALUES.Closed, TaskHelpers_1.TaskHelpers.isInClosedState],
    [GROUP_VALUES.Invalid, TaskHelpers_1.TaskHelpers.isInvalid]
]);
var groupKeys = Array.from(exports.groupFilter.keys());
var taskToGroupMapper = function (task) {
    var e_1, _a;
    var currentGrouping = GROUP_VALUES.General;
    try {
        for (var groupKeys_1 = __values(groupKeys), groupKeys_1_1 = groupKeys_1.next(); !groupKeys_1_1.done; groupKeys_1_1 = groupKeys_1.next()) {
            var groupKey = groupKeys_1_1.value;
            var filterFn = exports.groupFilter.get(groupKey);
            if (filterFn(task) === true) {
                currentGrouping = groupKey;
                break;
            }
        }
    }
    catch (e_1_1) { e_1 = { error: e_1_1 }; }
    finally {
        try {
            if (groupKeys_1_1 && !groupKeys_1_1.done && (_a = groupKeys_1.return)) _a.call(groupKeys_1);
        }
        finally { if (e_1) throw e_1.error; }
    }
    return currentGrouping;
};
exports.taskToGroupMapper = taskToGroupMapper;
var noteTypes;
(function (noteTypes) {
    noteTypes["TASK_NOTE"] = "TaskNote";
})(noteTypes = exports.noteTypes || (exports.noteTypes = {}));
var defaultExtractor = function (a) { return a; };
exports.defaultExtractor = defaultExtractor;
var taskExtractor = function (response) { return response.task; };
exports.taskExtractor = taskExtractor;
var successExtractor = function (response) { return response.success; };
exports.successExtractor = successExtractor;
var tasksExtractor = function (response) { return response.tasks; };
exports.tasksExtractor = tasksExtractor;
var childTasksExtractor = function (response) { return response.child_tasks; };
exports.childTasksExtractor = childTasksExtractor;
var locationExtractor = function (response) { return response.data; };
exports.locationExtractor = locationExtractor;
var scanCodeExtractor = function (response) { return response.scan_string; };
exports.scanCodeExtractor = scanCodeExtractor;
var taskIdsExtractor = function (response) { return response.task_ids; };
exports.taskIdsExtractor = taskIdsExtractor;
var formExtractor = function (response) { return response.form; };
exports.formExtractor = formExtractor;
var quotesExtractor = function (response) { return response.quotes; };
exports.quotesExtractor = quotesExtractor;
var answersExtractor = function (response) { return response.answers; };
exports.answersExtractor = answersExtractor;
var TaskRealTimeEvents;
(function (TaskRealTimeEvents) {
    TaskRealTimeEvents["TASK_UPDATE"] = "task update";
    TaskRealTimeEvents["WAYPOINT_ADDED"] = "waypoint added";
    TaskRealTimeEvents["WAYPOINT_DELETED"] = "waypoint deleted";
    TaskRealTimeEvents["WAYPOINT_UPDATED"] = "waypoint updated";
    TaskRealTimeEvents["NEW_SCAN"] = "new scan";
    TaskRealTimeEvents["NEW_NOTE"] = "new note";
    TaskRealTimeEvents["TASK_DELETED"] = "task deleted";
    TaskRealTimeEvents["NEW_TASK"] = "new task";
})(TaskRealTimeEvents = exports.TaskRealTimeEvents || (exports.TaskRealTimeEvents = {}));
exports.baseRoute = '/tasks';
exports.Routes = {
    GET_OPEN_TASKS: "".concat(exports.baseRoute, "/open"),
    GET_PLANNING_TASKS: "".concat(exports.baseRoute, "/planning"),
    GET_INVALID_TASKS: "".concat(exports.baseRoute, "/invalids"),
    GET_TASK: "".concat(exports.baseRoute, "/{:id}"),
    GET_CHILD_TASKS: "".concat(exports.baseRoute, "/{:id}/child_tasks"),
    BATCH_GET_TASK: "".concat(exports.baseRoute, "/batch_get"),
    GET_CLOSED_TASKS_WITH_QUERY: "".concat(exports.baseRoute, "/closed_with_query"),
    GET_HISTORY_TASKS: "/web".concat(exports.baseRoute, "/history"),
    GET_HISTORY_TASKS_METADATA: "/web".concat(exports.baseRoute, "/history/metadata"),
    UPDATE_TASK: "".concat(exports.baseRoute, "/{:id}"),
    CREATE_TASK: "".concat(exports.baseRoute),
    FINISH_TASK: "".concat(exports.baseRoute, "/{:id}/finish"),
    CANCEL_TASK: "".concat(exports.baseRoute, "/{:id}/cancel"),
    ACKNOWLEDGE_TASK: "".concat(exports.baseRoute, "/acknowledge_task"),
    MASS_TASK_ASSIGN: "".concat(exports.baseRoute, "/mass_assign"),
    MASS_TASK_UNASSIGN: "".concat(exports.baseRoute, "/mass_unassign"),
    MASS_TASK_CANCEL: "".concat(exports.baseRoute, "/mass_cancel"),
    MOVE_TASKS_TO_PLANNING: "".concat(exports.baseRoute, "/mark_not_ready_to_execute"),
    RELEASE_TASKS_TO_DRIVERS: "".concat(exports.baseRoute, "/release"),
    UPDATE_TASK_PREPARATION_STATUS: "".concat(exports.baseRoute, "/update_preparation_status"),
    GET_TASK_LOCATIONS: "".concat(exports.baseRoute, "/{:id}/locations"),
    CANCEL_ALL_OPEN_TASKS: "".concat(exports.baseRoute, "/cancel_all"),
    MASS_DELETE_GROUPS: "".concat(exports.baseRoute, "/mass_delete_groups"),
    HAS_DEFECTIVE_GEOCODE: "".concat(exports.baseRoute, "/has_defective_geocode"),
    GET_TASK_ACTIVITY_LOG: "".concat(exports.baseRoute, "/{:id}/history"),
    CHANGE_TASK_TEAM: "".concat(exports.baseRoute, "/{:id}/change_team"),
    UPDATE_TASKS_PRIORITIES: "".concat(exports.baseRoute, "/update_priorities"),
    LOCK_TASK: "".concat(exports.baseRoute, "/lock"),
    UNLOCK_TASK: "".concat(exports.baseRoute, "/unlock"),
    DUPLICATE_TASK: "".concat(exports.baseRoute, "/{:id}/duplicate"),
    RESCHEDULE_QUOTE: "".concat(exports.baseRoute, "/reschedule_quote"),
    RESCHEDULE_CANCELED: "".concat(exports.baseRoute, "/reschedule_cancelled"),
    GET_PICKUP_QR_CODE: "".concat(exports.baseRoute, "/{:id}/generate_pickup_qr_code"),
    RESCHEDULE_VIRTUAL_TASKS: "".concat(exports.baseRoute, "/reschedule_virtual_tasks"),
    FORM_SUBMIT: "".concat(exports.baseRoute, "/{:id}/way_points/{:way_point_id}/forms"),
    IMPORT_TASKS_CSV: "".concat(exports.baseRoute, "/import_from_csv"),
    BROADCAST_TO_DRIVERS: "".concat(exports.baseRoute, "/broadcast_to_drivers"),
    CREATE_TASK_NOTE: "".concat(exports.baseRoute, "/{:id}/way_points/{:way_point_id}/task_notes"),
    DELETE_WAYPOINT: "".concat(exports.baseRoute, "/{:id}/way_points/{:way_point_id}"),
    GET_WAYPOINT_ANSWERS: "".concat(exports.baseRoute, "/{:id}/way_points/{:way_point_id}/answers")
};
// keep this here in case we need, all this data is required by frontend currently
//const PLANNING_DEFAULT_PARAMS_REQUEST = "first_way_point_has_to_leave_by,active_way_point_id,status,id,way_points.all.position,group_leader_id,priority,late,customer_id,way_points.all.customer_id,way_points.all.id,payment_type_name,task_inventories.all.id,task_inventories.all.way_point_id,task_inventories.all.pending,task_inventories.all.inventory,task_inventories.all.original_quantity,ready_to_execute,virtual_task,done_planning,task_type_id,rogue_reasons,invalidated,automatically_assigned,external_id,title,tag_id,created_at,user_id,way_points.all.late,way_points.all.done,way_points.all.address,planning_done,scheduled_at,way_points.first.address,way_points.last.address,total_price,fleet_id,lat,lng,way_points.all.lat,way_points.all.lng,way_points.all.scheduled_at,team_ids,way_points.all.customer,way_points.all.eta,route_name,run,dispatcher_id,preparation_status,preparation_start_time_planned,preparation_end_time_planned,preparation_ready_for_pickup_time_planned,payment_method,preparation_external_id,fleet_delivery_external_id";
//const OPEN_DEFAULT_PARAMS_REQUEST = "first_way_point_has_to_leave_by,active_way_point_id,status,id,way_points.all.position,group_leader_id,priority,late,customer_id,way_points.all.customer_id,way_points.all.id,payment_type_name,task_inventories.all.id,task_inventories.all.way_point_id,task_inventories.all.pending,task_inventories.all.inventory,task_inventories.all.original_quantity,ready_to_execute,virtual_task,done_planning,task_type_id,rogue_reasons,invalidated,automatically_assigned,external_id,title,tag_id,created_at,user_id,way_points.all.late,way_points.all.done,way_points.all.address,planning_done,scheduled_at,way_points.first.address,way_points.last.address,total_price,fleet_id,lat,lng,way_points.all.lat,way_points.all.lng,way_points.all.scheduled_at,team_ids,way_points.all.customer,way_points.all.eta,route_name,run,dispatcher_id,preparation_status,preparation_start_time_planned,preparation_end_time_planned,preparation_ready_for_pickup_time_planned,payment_method,preparation_external_id,fleet_delivery_external_id";
exports.taskDefaultFields = [
    'id',
    'status',
    'invalidated',
    'group_leader_id',
    'ready_to_execute',
    { way_points: ['position'] }
];
//# sourceMappingURL=Tasks.consts.js.map