"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseRUMObjectTo022FormatString = parseRUMObjectTo022FormatString;
var string_1 = require("../../../string");
var shared_1 = require("../../shared");
var _022_format_za_record_1 = require("./022-format-za-record");
// Generate one RUM RSS 022 record line
function parseRUMObjectTo022FormatString(params) {
    var _a = params.FINESS, FINESS = _a === void 0 ? shared_1.DEFAULT_FINESS : _a, _b = params.RSS, RSS = _b === void 0 ? shared_1.DEFAULT_RSS : _b, _c = params.ADM, ADM = _c === void 0 ? shared_1.DEFAULT_ADM : _c, _d = params.RUM, RUM = _d === void 0 ? shared_1.DEFAULT_RUM : _d, _e = params.birthDate, birthDate = _e === void 0 ? shared_1.DEFAULT_BIRTH_DATE : _e, _f = params.sex, sex = _f === void 0 ? shared_1.DEFAULT_SEX : _f, _g = params.uMed, uMed = _g === void 0 ? shared_1.DEFAULT_U_MED : _g, _h = params.authorisation, authorisation = _h === void 0 ? shared_1.DEFAULT_AUTHORISATION : _h, _j = params.entryDate, entryDate = _j === void 0 ? shared_1.DEFAULT_ENTRY_DATE : _j, _k = params.entryMode, entryMode = _k === void 0 ? shared_1.DEFAULT_ENTRY_MODE : _k, _l = params.provenance, provenance = _l === void 0 ? shared_1.DEFAULT_PROVENANCE : _l, _m = params.exitDate, exitDate = _m === void 0 ? shared_1.DEFAULT_EXIT_DATE : _m, _o = params.exitMode, exitMode = _o === void 0 ? shared_1.DEFAULT_EXIT_MODE : _o, _p = params.destination, destination = _p === void 0 ? shared_1.DEFAULT_DESTINATION : _p, _q = params.cpRes, cpRes = _q === void 0 ? shared_1.DEFAULT_CP_RES : _q, _r = params.weight, weight = _r === void 0 ? shared_1.DEFAULT_WEIGHT : _r, _s = params.ageGestation, ageGestation = _s === void 0 ? shared_1.DEFAULT_AGE_GESTATION : _s, _t = params.lastMensDate, lastMensDate = _t === void 0 ? shared_1.DEFAULT_LAST_MENS_DATE : _t, _u = params.session, session = _u === void 0 ? shared_1.DEFAULT_SESSION : _u, _v = params.DP, DP = _v === void 0 ? shared_1.DEFAULT_DP : _v, _w = params.DR, DR = _w === void 0 ? shared_1.DEFAULT_DR : _w, _x = params.IGS, IGS = _x === void 0 ? shared_1.DEFAULT_IGS : _x, _y = params.conf, conf = _y === void 0 ? shared_1.DEFAULT_CONF : _y, _z = params.rtM, rtM = _z === void 0 ? shared_1.DEFAULT_RT_M : _z, _0 = params.rtD, rtD = _0 === void 0 ? shared_1.DEFAULT_RT_D : _0, _1 = params.innov, innov = _1 === void 0 ? shared_1.DEFAULT_INNOV : _1, _2 = params.conv, conv = _2 === void 0 ? shared_1.DEFAULT_CONV : _2, _3 = params.raac, raac = _3 === void 0 ? shared_1.DEFAULT_RAAC : _3, _4 = params.spec, spec = _4 === void 0 ? shared_1.DEFAULT_SPEC : _4, _5 = params.RH, RH = _5 === void 0 ? shared_1.DEFAULT_RH : _5, _6 = params.tarif, tarif = _6 === void 0 ? shared_1.DEFAULT_TARIF : _6, _7 = params.cat, cat = _7 === void 0 ? shared_1.DEFAULT_CAT : _7, _8 = params.NP, NP = _8 === void 0 ? shared_1.DEFAULT_NP : _8, _9 = params.ER, ER = _9 === void 0 ? shared_1.DEFAULT_ER : _9, _10 = params.FILL, FILL = _10 === void 0 ? shared_1.DEFAULT_FILL : _10, _11 = params.RES, RES = _11 === void 0 ? shared_1.DEFAULT_RES : _11, _12 = params.DAs, DAs = _12 === void 0 ? [] : _12, _13 = params.DADs, DADs = _13 === void 0 ? [] : _13, _14 = params.ZAs, ZAs = _14 === void 0 ? [] : _14;
    var _15 = params.nDA, nDA = _15 === void 0 ? DAs.length : _15, _16 = params.nDAD, nDAD = _16 === void 0 ? DADs.length : _16, _17 = params.nZA, nZA = _17 === void 0 ? ZAs.length : _17;
    var fixed = [
        (0, string_1.pad)(FINESS, 9, string_1.Alignment.LEFT),
        shared_1.DEFAULT_022_RSS_FORMAT, // Format version
        (0, string_1.pad)(RSS, 20, string_1.Alignment.LEFT),
        (0, string_1.pad)(ADM, 20, string_1.Alignment.LEFT),
        (0, string_1.pad)(RUM, 10, string_1.Alignment.LEFT),
        birthDate,
        sex,
        (0, string_1.pad)(uMed, 4, string_1.Alignment.LEFT),
        (0, string_1.pad)(authorisation !== null && authorisation !== void 0 ? authorisation : '', 2, string_1.Alignment.LEFT),
        entryDate,
        entryMode,
        (0, string_1.pad)(provenance, 1, string_1.Alignment.LEFT),
        exitDate,
        exitMode,
        (0, string_1.pad)(destination, 1, string_1.Alignment.LEFT),
        cpRes,
        (0, string_1.pad)(weight, 4, string_1.Alignment.RIGHT, weight && weight.length > 0 ? '0' : ' '),
        (0, string_1.pad)(ageGestation, 2, string_1.Alignment.RIGHT, ageGestation && ageGestation.length > 0 ? '0' : ' '),
        (0, string_1.pad)(lastMensDate, 8, string_1.Alignment.LEFT, ' '),
        (0, string_1.pad)(session.toString(), 2, string_1.Alignment.RIGHT, '0'),
        (0, string_1.pad)(nDA.toString(), 2, string_1.Alignment.RIGHT, '0'),
        (0, string_1.pad)(nDAD.toString(), 2, string_1.Alignment.RIGHT, '0'),
        (0, string_1.pad)(nZA.toString(), 3, string_1.Alignment.RIGHT, '0'),
        (0, string_1.pad)(DP, 8, string_1.Alignment.LEFT),
        (0, string_1.pad)(DR, 8, string_1.Alignment.LEFT),
        (0, string_1.pad)(IGS, 3, string_1.Alignment.RIGHT, '0'),
        (0, string_1.pad)(conf !== null && conf !== void 0 ? conf : '', 1, string_1.Alignment.LEFT),
        (0, string_1.pad)(rtM, 1, string_1.Alignment.LEFT),
        (0, string_1.pad)(rtD, 1, string_1.Alignment.LEFT),
        (0, string_1.pad)(innov, 15, string_1.Alignment.LEFT),
        (0, string_1.pad)(conv, 1, string_1.Alignment.LEFT),
        (0, string_1.pad)(raac, 1, string_1.Alignment.LEFT),
        (0, string_1.pad)(spec, 1, string_1.Alignment.LEFT),
        (0, string_1.pad)(RH, 1, string_1.Alignment.LEFT),
        (0, string_1.pad)(tarif, 1, string_1.Alignment.LEFT),
        (0, string_1.pad)(cat, 1, string_1.Alignment.LEFT),
        (0, string_1.pad)(NP, 1, string_1.Alignment.LEFT),
        (0, string_1.pad)(ER, 1, string_1.Alignment.LEFT),
        (0, string_1.pad)(FILL, 4, string_1.Alignment.LEFT),
        (0, string_1.pad)(RES, 3, string_1.Alignment.LEFT)
    ];
    var das = DAs.map(function (code) { return (0, string_1.pad)(code, 8, string_1.Alignment.LEFT); }).join('');
    var dads = DADs.map(function (code) { return (0, string_1.pad)(code, 8, string_1.Alignment.LEFT); }).join('');
    var zas = ZAs.map(_022_format_za_record_1.formatZARecord).join('');
    var result = __spreadArray(__spreadArray([], fixed, true), [das, dads, zas], false).join('');
    return result;
}
