"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatZAExt = void 0;
exports.formatZARecord = formatZARecord;
var string_1 = require("../../../string");
// Format a single ZA record into a padded string
function formatZARecord(za) {
    var _a, _b, _c, _d, _e, _f, _g;
    return [
        (0, string_1.pad)(za.date, 8),
        (0, string_1.pad)(za.code, 7),
        (0, exports.formatZAExt)(za.ext),
        (0, string_1.pad)((_a = za.phase) !== null && _a !== void 0 ? _a : '', 1),
        (0, string_1.pad)((_b = za.act) !== null && _b !== void 0 ? _b : '', 1),
        (0, string_1.pad)((_c = za.diag) !== null && _c !== void 0 ? _c : '', 1),
        (0, string_1.pad)((_d = za.mod) !== null && _d !== void 0 ? _d : '', 4),
        (0, string_1.pad)((_e = za.RE) !== null && _e !== void 0 ? _e : '', 1),
        (0, string_1.pad)((_f = za.AN) !== null && _f !== void 0 ? _f : '', 1),
        (0, string_1.pad)((_g = za.qty) !== null && _g !== void 0 ? _g : '', 2, string_1.Alignment.RIGHT, '0')
    ].join('');
}
var formatZAExt = function (ext) {
    if (!ext)
        return '   ';
    switch (ext.length) {
        case 1:
            return "-0".concat(ext);
        case 2:
            return "-".concat(ext);
        case 3:
            if (ext.startsWith('-'))
                return "".concat(ext);
            throw new Error("Invalid ZA ext length: ".concat(ext));
        default:
            throw new Error("Invalid ZA ext length: ".concat(ext));
    }
};
exports.formatZAExt = formatZAExt;
