"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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProfitabilityWithTemporaryList = exports.ProfitabilityWithtemporary = exports.FinancialEntry = exports.Exchange = void 0;
const jackson_js_1 = require("jackson-js");
const date_1 = require("../jack-x/date");
const tag_1 = require("../tag/tag");
const lodash_1 = __importDefault(require("lodash"));
class Exchange {
    constructor(amount, currency) {
        this.setOriginal = () => {
            this.original = true;
        };
        this.amount = amount;
        this.currency = currency;
    }
}
__decorate([
    (0, jackson_js_1.JsonProperty)()
], Exchange.prototype, "amount", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)()
], Exchange.prototype, "currency", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)()
], Exchange.prototype, "original", void 0);
exports.Exchange = Exchange;
class FinancialEntry {
    constructor() {
        this.date = new Date();
        this.identifier = "";
        this.tag = new tag_1.Tag("");
        this.keys = [];
        this.exchanges = [];
    }
    getOriginalExchange() {
        return lodash_1.default.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 = lodash_1.default.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([
    (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] })
], FinancialEntry.prototype, "date", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)()
], FinancialEntry.prototype, "identifier", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [Array, [String]] })
], FinancialEntry.prototype, "keys", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [tag_1.Tag] })
], FinancialEntry.prototype, "tag", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [Array, [Exchange]] })
], FinancialEntry.prototype, "exchanges", void 0);
exports.FinancialEntry = FinancialEntry;
class ProfitabilityWithtemporary {
    constructor() {
        this.entries = [];
    }
}
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [Array, [FinancialEntry]] })
], ProfitabilityWithtemporary.prototype, "entries", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)()
], ProfitabilityWithtemporary.prototype, "verified", void 0);
exports.ProfitabilityWithtemporary = ProfitabilityWithtemporary;
class ProfitabilityWithTemporaryList {
    constructor() {
        this.result = {};
    }
    get(identifier) {
        return this.result[identifier];
    }
    set(identifier, res) {
        this.result[identifier] = res;
    }
}
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [Object, [String, ProfitabilityWithTemporaryList]] })
], ProfitabilityWithTemporaryList.prototype, "result", void 0);
exports.ProfitabilityWithTemporaryList = ProfitabilityWithTemporaryList;
//# sourceMappingURL=financial_entry.js.map