"use strict";
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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Expense = exports.Payment = exports.ExpenseRelation = exports.ExpenseWeightType = exports.ExpenseClass = void 0;
const jackson_js_1 = require("jackson-js");
const date_1 = require("../jack-x/date");
const message_1 = require("../message");
const namespace_1 = require("../message/namespace");
const financial_entry_1 = require("./financial_entry");
var ExpenseClass;
(function (ExpenseClass) {
    ExpenseClass["INBOUND_SHIPMENT"] = "IS";
    ExpenseClass["ORDER"] = "ORD";
    ExpenseClass["PURCHASE_ORDER"] = "PO";
    ExpenseClass["ITEM"] = "ITM";
    ExpenseClass["STORE"] = "STR";
})(ExpenseClass = exports.ExpenseClass || (exports.ExpenseClass = {}));
var ExpenseWeightType;
(function (ExpenseWeightType) {
    ExpenseWeightType["VOLUMETRIC"] = "VOLUMETRIC";
    ExpenseWeightType["UNITARY"] = "UNITARY";
    ExpenseWeightType["MONETARY"] = "MONETARY";
})(ExpenseWeightType = exports.ExpenseWeightType || (exports.ExpenseWeightType = {}));
class ExpenseRelation {
    constructor(targetId, weight) {
        this.targetId = targetId;
        this.weight = weight;
    }
}
__decorate([
    (0, jackson_js_1.JsonProperty)()
], ExpenseRelation.prototype, "targetId", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)()
], ExpenseRelation.prototype, "weight", void 0);
exports.ExpenseRelation = ExpenseRelation;
class Payment {
    constructor(id, date, amount) {
        this.id = id;
        this.date = date;
        this.amount = amount;
        this.vat = undefined;
    }
}
__decorate([
    (0, jackson_js_1.JsonProperty)()
], Payment.prototype, "id", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonSerialize)({ using: date_1.DateSerializer.serialize }),
    (0, jackson_js_1.JsonDeserialize)({ using: date_1.DateSerializer.deserialize }),
    (0, jackson_js_1.JsonClassType)({ type: () => [Date] })
], Payment.prototype, "date", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [financial_entry_1.FinancialEntry] })
], Payment.prototype, "vat", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [financial_entry_1.FinancialEntry] })
], Payment.prototype, "amount", void 0);
exports.Payment = Payment;
class Expense {
    constructor(id, accoundableEntity, purchaseDate, _class) {
        this.strip = () => {
            this.note = "";
        };
        this.buildMessage = (storeId, service, verb, payloadEnricher) => {
            let tmn;
            let trn;
            switch (this.class) {
                case ExpenseClass.PURCHASE_ORDER: {
                    tmn = message_1.TMN.NewEventTMN(namespace_1.TMN_NAMESPACE_TECHNITY, namespace_1.TMN_TECHNITY_RESOURCE_TYPE_PURCHASE_ORDERS, namespace_1.TMN_TECHNITY_RESOURCE_SUBTYPE_EXPENSES);
                    trn = message_1.TRN.NewTRN(storeId, namespace_1.TRN_NAMESPACE_TECHNITY, namespace_1.TRN_TECHNITY_RESOURCE_TYPE_PURCHASE_ORDERS, this.accountableEntity);
                    break;
                }
                default: {
                    throw (`uninplemented expense class message [${this.class}]`);
                }
            }
            const payload = payloadEnricher(this);
            return new message_1.EventMessage(tmn, trn, message_1.TRN.NewTRN(message_1.TRN_TECHNITY_PARENT, namespace_1.TRN_NAMESPACE_SERVICE, service, process.pid.toString()), { Verb: verb, Payload: payload });
        };
        this.id = id;
        this.accountableEntity = accoundableEntity;
        this.purchaseDate = purchaseDate;
        this.title = "";
        this.class = _class;
        this.note = "";
        this.weightType = ExpenseWeightType.UNITARY;
        this.label = "";
        this.payments = [];
        this.relations = [];
    }
}
__decorate([
    (0, jackson_js_1.JsonProperty)()
], Expense.prototype, "id", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)()
], Expense.prototype, "accountableEntity", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonSerialize)({ using: date_1.DateSerializer.serialize }),
    (0, jackson_js_1.JsonDeserialize)({ using: date_1.DateSerializer.deserialize }),
    (0, jackson_js_1.JsonClassType)({ type: () => [Date] })
], Expense.prototype, "purchaseDate", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)()
], Expense.prototype, "title", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)()
], Expense.prototype, "note", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)()
], Expense.prototype, "label", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)()
], Expense.prototype, "class", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)()
], Expense.prototype, "weightType", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [Array, [Payment]] })
], Expense.prototype, "payments", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [Array, [ExpenseRelation]] })
], Expense.prototype, "relations", void 0);
exports.Expense = Expense;
//# sourceMappingURL=expense.js.map