"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BorrowOrder = void 0;
const kit_1 = require("@solana/kit"); // eslint-disable-line @typescript-eslint/no-unused-vars
const bn_js_1 = __importDefault(require("bn.js")); // eslint-disable-line @typescript-eslint/no-unused-vars
const borsh = __importStar(require("@coral-xyz/borsh"));
const utils_1 = require("../utils");
class BorrowOrder {
    debtLiquidityMint;
    remainingDebtAmount;
    filledDebtDestination;
    minDebtTermSeconds;
    fillableUntilTimestamp;
    placedAtTimestamp;
    lastUpdatedAtTimestamp;
    requestedDebtAmount;
    maxBorrowRateBps;
    active;
    enableAutoRolloverOnFilledBorrows;
    padding1;
    endPadding;
    constructor(fields) {
        this.debtLiquidityMint = fields.debtLiquidityMint;
        this.remainingDebtAmount = fields.remainingDebtAmount;
        this.filledDebtDestination = fields.filledDebtDestination;
        this.minDebtTermSeconds = fields.minDebtTermSeconds;
        this.fillableUntilTimestamp = fields.fillableUntilTimestamp;
        this.placedAtTimestamp = fields.placedAtTimestamp;
        this.lastUpdatedAtTimestamp = fields.lastUpdatedAtTimestamp;
        this.requestedDebtAmount = fields.requestedDebtAmount;
        this.maxBorrowRateBps = fields.maxBorrowRateBps;
        this.active = fields.active;
        this.enableAutoRolloverOnFilledBorrows =
            fields.enableAutoRolloverOnFilledBorrows;
        this.padding1 = fields.padding1;
        this.endPadding = fields.endPadding;
    }
    static layout(property) {
        return borsh.struct([
            (0, utils_1.borshAddress)("debtLiquidityMint"),
            borsh.u64("remainingDebtAmount"),
            (0, utils_1.borshAddress)("filledDebtDestination"),
            borsh.u64("minDebtTermSeconds"),
            borsh.u64("fillableUntilTimestamp"),
            borsh.u64("placedAtTimestamp"),
            borsh.u64("lastUpdatedAtTimestamp"),
            borsh.u64("requestedDebtAmount"),
            borsh.u32("maxBorrowRateBps"),
            borsh.u8("active"),
            borsh.u8("enableAutoRolloverOnFilledBorrows"),
            borsh.array(borsh.u8(), 2, "padding1"),
            borsh.array(borsh.u64(), 5, "endPadding"),
        ], property);
    }
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    static fromDecoded(obj) {
        return new BorrowOrder({
            debtLiquidityMint: obj.debtLiquidityMint,
            remainingDebtAmount: obj.remainingDebtAmount,
            filledDebtDestination: obj.filledDebtDestination,
            minDebtTermSeconds: obj.minDebtTermSeconds,
            fillableUntilTimestamp: obj.fillableUntilTimestamp,
            placedAtTimestamp: obj.placedAtTimestamp,
            lastUpdatedAtTimestamp: obj.lastUpdatedAtTimestamp,
            requestedDebtAmount: obj.requestedDebtAmount,
            maxBorrowRateBps: obj.maxBorrowRateBps,
            active: obj.active,
            enableAutoRolloverOnFilledBorrows: obj.enableAutoRolloverOnFilledBorrows,
            padding1: obj.padding1,
            endPadding: obj.endPadding,
        });
    }
    static toEncodable(fields) {
        return {
            debtLiquidityMint: fields.debtLiquidityMint,
            remainingDebtAmount: fields.remainingDebtAmount,
            filledDebtDestination: fields.filledDebtDestination,
            minDebtTermSeconds: fields.minDebtTermSeconds,
            fillableUntilTimestamp: fields.fillableUntilTimestamp,
            placedAtTimestamp: fields.placedAtTimestamp,
            lastUpdatedAtTimestamp: fields.lastUpdatedAtTimestamp,
            requestedDebtAmount: fields.requestedDebtAmount,
            maxBorrowRateBps: fields.maxBorrowRateBps,
            active: fields.active,
            enableAutoRolloverOnFilledBorrows: fields.enableAutoRolloverOnFilledBorrows,
            padding1: fields.padding1,
            endPadding: fields.endPadding,
        };
    }
    toJSON() {
        return {
            debtLiquidityMint: this.debtLiquidityMint,
            remainingDebtAmount: this.remainingDebtAmount.toString(),
            filledDebtDestination: this.filledDebtDestination,
            minDebtTermSeconds: this.minDebtTermSeconds.toString(),
            fillableUntilTimestamp: this.fillableUntilTimestamp.toString(),
            placedAtTimestamp: this.placedAtTimestamp.toString(),
            lastUpdatedAtTimestamp: this.lastUpdatedAtTimestamp.toString(),
            requestedDebtAmount: this.requestedDebtAmount.toString(),
            maxBorrowRateBps: this.maxBorrowRateBps,
            active: this.active,
            enableAutoRolloverOnFilledBorrows: this.enableAutoRolloverOnFilledBorrows,
            padding1: this.padding1,
            endPadding: this.endPadding.map((item) => item.toString()),
        };
    }
    static fromJSON(obj) {
        return new BorrowOrder({
            debtLiquidityMint: (0, kit_1.address)(obj.debtLiquidityMint),
            remainingDebtAmount: new bn_js_1.default(obj.remainingDebtAmount),
            filledDebtDestination: (0, kit_1.address)(obj.filledDebtDestination),
            minDebtTermSeconds: new bn_js_1.default(obj.minDebtTermSeconds),
            fillableUntilTimestamp: new bn_js_1.default(obj.fillableUntilTimestamp),
            placedAtTimestamp: new bn_js_1.default(obj.placedAtTimestamp),
            lastUpdatedAtTimestamp: new bn_js_1.default(obj.lastUpdatedAtTimestamp),
            requestedDebtAmount: new bn_js_1.default(obj.requestedDebtAmount),
            maxBorrowRateBps: obj.maxBorrowRateBps,
            active: obj.active,
            enableAutoRolloverOnFilledBorrows: obj.enableAutoRolloverOnFilledBorrows,
            padding1: obj.padding1,
            endPadding: obj.endPadding.map((item) => new bn_js_1.default(item)),
        });
    }
    toEncodable() {
        return BorrowOrder.toEncodable(this);
    }
}
exports.BorrowOrder = BorrowOrder;
//# sourceMappingURL=BorrowOrder.js.map