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, JsonProperty } from "jackson-js";
import { TagCategory, TagNamespace, TagDiscriminator, Tag } from "../tag";
export var Contributions;
(function (Contributions) {
    Contributions["NET_REVENUE"] = "net_revenue";
    Contributions["VAT_REVENUE"] = "vat_revenue";
    Contributions["NET_PROMOTIONS"] = "net_promotions";
    Contributions["VAT_PROMOTIONS"] = "vat_promotions";
    Contributions["NET_PROFIT"] = "net_profit";
    Contributions["VAT_PROFIT"] = "vat_profit";
    Contributions["NET_MARGIN"] = "net_margin";
    Contributions["VAT_MARGIN"] = "vat_margin";
    Contributions["NET_SALE_PROFIT"] = "net_sale_income";
    Contributions["VAT_SALE_INCOME"] = "vat_sale_income";
    Contributions["NET_ADV_COST"] = "net_adv_cost";
    Contributions["VAT_ADV_COST"] = "vat_adv_cost";
    Contributions["NET_EXTERNAL_EXPENSES"] = "net_external_expenses";
    Contributions["VAT_EXTERNAL_EXPENSES"] = "vat_external_expenses";
    Contributions["NET_COGS"] = "net_cogs";
    Contributions["VAT_COGS"] = "vat_cogs";
    Contributions["NET_FEES"] = "net_fees";
    Contributions["VAT_FEES"] = "vat_fees";
    Contributions["NET_RETURNS_VALUE"] = "net_returns_value";
    Contributions["VAT_RETURNS_VALUE"] = "vat_returns_value";
    Contributions["NET_REIMBURSEMENT_VALUE"] = "net_reimbursement_value";
    Contributions["VAT_REIMBURSEMENT_VALUE"] = "vat_reimbursement_value";
    Contributions["NET_OPERATIONS"] = "net_operations";
    Contributions["VAT_OPERATIONS"] = "vat_operations";
    Contributions["GROSS_REVENUE"] = "gross_revenue";
    Contributions["PROMOTIONS"] = "promotions";
    Contributions["GROSS_PROFIT"] = "gross_profit";
    Contributions["GROSS_MARGIN"] = "gross_margin";
    Contributions["SALE_NET_PROFIT"] = "sale_net_profit";
    Contributions["ADV_COST"] = "adv_cost";
    Contributions["EXTERNAL_EXPENSES"] = "external_expenses";
    Contributions["COGS"] = "cogs";
    Contributions["FEES"] = "fees";
    Contributions["TAX_IN"] = "tax_in";
    Contributions["TAX_OUT"] = "tax_out";
    Contributions["RETURNS_VALUE"] = "returns_value";
    Contributions["REIMBURSEMENT_VALUE"] = "reimbursement_value";
    Contributions["OPERATIONS"] = "operations";
})(Contributions || (Contributions = {}));
export class FinancialEntryType {
    constructor(tag) {
        if (!tag) {
            this.tag = new Tag("");
        }
        else {
            this.setup(tag);
        }
        this.contributesTo = [];
    }
    setup(tag) {
        this.tag = tag;
        this.contributesTo = [];
        const tagCategory = this.tag.getCategory();
        const tagNamespace = this.tag.getNamespace();
        this.contributesTo = this.contributesTo.concat(this.contributorsFromTagCategory(tagCategory, this.tag.discriminator()));
        this.contributesTo = this.contributesTo.concat(this.contributorsFromTagNamespace(tagNamespace, this.tag.discriminator()));
        this.contributesTo = this.contributesTo.concat(this.contributorsFromTagDiscriminator(this.tag));
    }
    contributorsFromTagCategory(category, discriminator) {
        const categoryContributions = [];
        switch (category) {
            case TagCategory.FEE:
                categoryContributions.push(Contributions.FEES);
                return categoryContributions;
            case TagCategory.REIMBURSEMENT:
                categoryContributions.push(Contributions.REIMBURSEMENT_VALUE);
                return categoryContributions;
            case TagCategory.SALE:
                categoryContributions.push(Contributions.SALE_NET_PROFIT);
                categoryContributions.push(Contributions.GROSS_REVENUE);
                categoryContributions.push(Contributions.NET_REVENUE);
                categoryContributions.push(Contributions.GROSS_MARGIN);
                categoryContributions.push(Contributions.NET_MARGIN);
                categoryContributions.push(Contributions.GROSS_PROFIT);
                categoryContributions.push(Contributions.NET_PROFIT);
                return categoryContributions;
            case TagCategory.REFUND:
                categoryContributions.push(Contributions.RETURNS_VALUE);
                return categoryContributions;
            case TagCategory.REVENUE:
                categoryContributions.push(Contributions.GROSS_REVENUE);
                return categoryContributions;
            default:
                return [];
        }
    }
    contributorsFromTagNamespace(namespace, discriminator) {
        const categoryContributions = [];
        switch (namespace) {
            case TagNamespace.EXPENSE:
                categoryContributions.push(Contributions.NET_PROFIT);
                categoryContributions.push(Contributions.NET_MARGIN);
                categoryContributions.push(Contributions.EXTERNAL_EXPENSES);
                return categoryContributions;
            case TagNamespace.ORDER:
                categoryContributions.push(Contributions.SALE_NET_PROFIT);
                return categoryContributions;
            case TagNamespace.ADVERTISING:
                categoryContributions.push(Contributions.ADV_COST);
                return categoryContributions;
            case TagNamespace.COGS:
                categoryContributions.push(Contributions.SALE_NET_PROFIT);
                categoryContributions.push(Contributions.GROSS_PROFIT);
                categoryContributions.push(Contributions.NET_PROFIT);
                categoryContributions.push(Contributions.GROSS_MARGIN);
                categoryContributions.push(Contributions.NET_MARGIN);
                categoryContributions.push(Contributions.COGS);
                return categoryContributions;
            case TagNamespace.OPERATION:
                categoryContributions.push(Contributions.OPERATIONS);
                return categoryContributions;
            default:
                return [];
        }
    }
    contributorsFromTagDiscriminator(tag) {
        if (tag.discriminator() != TagDiscriminator.VAT) {
            return [];
        }
        if (tag.getCategory() == TagCategory.SALE) {
            return [Contributions.TAX_OUT];
        }
        return [Contributions.TAX_IN];
    }
}
__decorate([
    JsonProperty(),
    JsonClassType({ type: () => [Tag] })
], FinancialEntryType.prototype, "tag", void 0);
__decorate([
    JsonProperty(),
    JsonClassType({ type: () => [Array, [String]] })
], FinancialEntryType.prototype, "contributesTo", void 0);
//# sourceMappingURL=financial_entry_type.js.map