#pragma once

#include <xrpl/tx/Transactor.h>

namespace xrpl {

class LoanManage : public Transactor
{
public:
    static constexpr ConsequencesFactoryType ConsequencesFactory{Normal};

    explicit LoanManage(ApplyContext& ctx) : Transactor(ctx)
    {
    }

    static bool
    checkExtraFeatures(PreflightContext const& ctx);

    static std::uint32_t
    getFlagsMask(PreflightContext const& ctx);

    static NotTEC
    preflight(PreflightContext const& ctx);

    static TER
    preclaim(PreclaimContext const& ctx);

    /** Helper function that might be needed by other transactors
     */
    static TER
    defaultLoan(
        ApplyView& view,
        SLE::ref loanSle,
        SLE::ref brokerSle,
        SLE::ref vaultSle,
        Asset const& vaultAsset,
        beast::Journal j);

    /** Helper function that might be needed by other transactors
     */
    static TER
    impairLoan(
        ApplyView& view,
        SLE::ref loanSle,
        SLE::ref vaultSle,
        Asset const& vaultAsset,
        beast::Journal j);

    /** Helper function that might be needed by other transactors
     */
    [[nodiscard]] static TER
    unimpairLoan(
        ApplyView& view,
        SLE::ref loanSle,
        SLE::ref vaultSle,
        Asset const& vaultAsset,
        beast::Journal j);

    TER
    doApply() override;
};

//------------------------------------------------------------------------------

}  // namespace xrpl
