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;
};
import { JsonClassType, JsonDeserialize, JsonProperty, JsonSerialize } from "jackson-js";
import { DateSerializer } from "../jack-x/date";
import { EventMessage, TMN, TRN, TRN_TECHNITY_PARENT } from "../message";
import { TMN_NAMESPACE_TECHNITY, TMN_TECHNITY_RESOURCE_TYPE_PURCHASE_ORDERS, TMN_TECHNITY_RESOURCE_SUBTYPE_EXPENSES, TRN_NAMESPACE_SERVICE, TRN_NAMESPACE_TECHNITY, TRN_TECHNITY_RESOURCE_TYPE_PURCHASE_ORDERS } from "../message/namespace";
import { FinancialEntry } from "./financial_entry";
export var ExpenseClass;
(function (ExpenseClass) {
    ExpenseClass["INBOUND_SHIPMENT"] = "IS";
    ExpenseClass["ORDER"] = "ORD";
    ExpenseClass["PURCHASE_ORDER"] = "PO";
    ExpenseClass["ITEM"] = "ITM";
    ExpenseClass["STORE"] = "STR";
})(ExpenseClass || (ExpenseClass = {}));
export var ExpenseWeightType;
(function (ExpenseWeightType) {
    ExpenseWeightType["VOLUMETRIC"] = "VOLUMETRIC";
    ExpenseWeightType["UNITARY"] = "UNITARY";
    ExpenseWeightType["MONETARY"] = "MONETARY";
})(ExpenseWeightType || (ExpenseWeightType = {}));
export class ExpenseRelation {
    constructor(targetId, weight) {
        this.targetId = targetId;
        this.weight = weight;
    }
}
__decorate([
    JsonProperty()
], ExpenseRelation.prototype, "targetId", void 0);
__decorate([
    JsonProperty()
], ExpenseRelation.prototype, "weight", void 0);
export class Payment {
    constructor(id, date, amount) {
        this.id = id;
        this.date = date;
        this.amount = amount;
        this.vat = undefined;
    }
}
__decorate([
    JsonProperty()
], Payment.prototype, "id", void 0);
__decorate([
    JsonProperty(),
    JsonSerialize({ using: DateSerializer.serialize }),
    JsonDeserialize({ using: DateSerializer.deserialize }),
    JsonClassType({ type: () => [Date] })
], Payment.prototype, "date", void 0);
__decorate([
    JsonProperty(),
    JsonClassType({ type: () => [FinancialEntry] })
], Payment.prototype, "vat", void 0);
__decorate([
    JsonProperty(),
    JsonClassType({ type: () => [FinancialEntry] })
], Payment.prototype, "amount", void 0);
export 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 = TMN.NewEventTMN(TMN_NAMESPACE_TECHNITY, TMN_TECHNITY_RESOURCE_TYPE_PURCHASE_ORDERS, TMN_TECHNITY_RESOURCE_SUBTYPE_EXPENSES);
                    trn = TRN.NewTRN(storeId, TRN_NAMESPACE_TECHNITY, TRN_TECHNITY_RESOURCE_TYPE_PURCHASE_ORDERS, this.accountableEntity);
                    break;
                }
                default: {
                    throw (`uninplemented expense class message [${this.class}]`);
                }
            }
            const payload = payloadEnricher(this);
            return new EventMessage(tmn, trn, TRN.NewTRN(TRN_TECHNITY_PARENT, 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([
    JsonProperty()
], Expense.prototype, "id", void 0);
__decorate([
    JsonProperty()
], Expense.prototype, "accountableEntity", void 0);
__decorate([
    JsonProperty(),
    JsonSerialize({ using: DateSerializer.serialize }),
    JsonDeserialize({ using: DateSerializer.deserialize }),
    JsonClassType({ type: () => [Date] })
], Expense.prototype, "purchaseDate", void 0);
__decorate([
    JsonProperty()
], Expense.prototype, "title", void 0);
__decorate([
    JsonProperty()
], Expense.prototype, "note", void 0);
__decorate([
    JsonProperty()
], Expense.prototype, "label", void 0);
__decorate([
    JsonProperty()
], Expense.prototype, "class", void 0);
__decorate([
    JsonProperty()
], Expense.prototype, "weightType", void 0);
__decorate([
    JsonProperty(),
    JsonClassType({ type: () => [Array, [Payment]] })
], Expense.prototype, "payments", void 0);
__decorate([
    JsonProperty(),
    JsonClassType({ type: () => [Array, [ExpenseRelation]] })
], Expense.prototype, "relations", void 0);
//# sourceMappingURL=expense.js.map