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 { Tag } from "../tag/tag";
import _ from "lodash";
export class Exchange {
    constructor(amount, currency) {
        this.setOriginal = () => {
            this.original = true;
        };
        this.amount = amount;
        this.currency = currency;
    }
}
__decorate([
    JsonProperty()
], Exchange.prototype, "amount", void 0);
__decorate([
    JsonProperty()
], Exchange.prototype, "currency", void 0);
__decorate([
    JsonProperty()
], Exchange.prototype, "original", void 0);
export class FinancialEntry {
    constructor() {
        this.date = new Date();
        this.identifier = "";
        this.tag = new Tag("");
        this.keys = [];
        this.exchanges = [];
    }
    getOriginalExchange() {
        return _.find(this.exchanges, (e) => e.original == true);
    }
    /* if currency is undefined or empty, get the original cost */
    cloneFilteredExchange(currency) {
        const newFE = new FinancialEntry();
        newFE.date = this.date;
        newFE.identifier = this.identifier;
        newFE.keys = this.keys;
        newFE.tag = this.tag;
        newFE.exchanges = _.filter(this.exchanges, (e) => {
            if (!(currency === null || currency === void 0 ? void 0 : currency.length)) {
                return e.original == true;
            }
            return e.currency == currency;
        });
        return newFE;
    }
}
__decorate([
    JsonProperty(),
    JsonSerialize({ using: DateSerializer.serialize }),
    JsonDeserialize({ using: DateSerializer.deserialize }),
    JsonClassType({ type: () => [Date] })
], FinancialEntry.prototype, "date", void 0);
__decorate([
    JsonProperty()
], FinancialEntry.prototype, "identifier", void 0);
__decorate([
    JsonProperty(),
    JsonClassType({ type: () => [Array, [String]] })
], FinancialEntry.prototype, "keys", void 0);
__decorate([
    JsonProperty(),
    JsonClassType({ type: () => [Tag] })
], FinancialEntry.prototype, "tag", void 0);
__decorate([
    JsonProperty(),
    JsonClassType({ type: () => [Array, [Exchange]] })
], FinancialEntry.prototype, "exchanges", void 0);
export class ProfitabilityWithtemporary {
    constructor() {
        this.entries = [];
    }
}
__decorate([
    JsonProperty(),
    JsonClassType({ type: () => [Array, [FinancialEntry]] })
], ProfitabilityWithtemporary.prototype, "entries", void 0);
__decorate([
    JsonProperty()
], ProfitabilityWithtemporary.prototype, "verified", void 0);
export class ProfitabilityWithTemporaryList {
    constructor() {
        this.result = {};
    }
    get(identifier) {
        return this.result[identifier];
    }
    set(identifier, res) {
        this.result[identifier] = res;
    }
}
__decorate([
    JsonProperty(),
    JsonClassType({ type: () => [Object, [String, ProfitabilityWithTemporaryList]] })
], ProfitabilityWithTemporaryList.prototype, "result", void 0);
//# sourceMappingURL=financial_entry.js.map