Home /Modules/citizen/BankAccount.sleela

BankAccount.sleela

lib/citizen/BankAccount.sleela · 163 line(s) · sleela

<< lib/citizen/BankAccount.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines BankAccount, the civic-finance Master Class — the quiet
     place a Citizen's money goes to be anxious. It models a single banking
     relationship: who you bank with, the routing + account numbers that get the
     money there, and the balance that is somehow always lower than you expect.
   
   BankAccount is a NATURAL / LOADABLE MODULE sharing the common module contract
   (load / loaded / moduleName / describe). It is a sidecar owned by Citizen and
   carries the real banking details: a 9-digit ABA routing number (the first two
   digits of which the Federal Reserve uses to decide which of its twelve
   Districts your money reports to) and an account number. It holds balance
   state in whole cents to keep the pennies honest.
   
   Family: citizen. Settlement crosses an explicit bridge to the ledger and the
   FederalReserveID clearing fabric. >>
#sleela 2.5
material;
< Unified SLeeLa SDK front-end object. >
class BankAccount {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 10294;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-10-16";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-07";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 9;
  < metaNationalSchedule: a real, citable instrument or "none" >
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }

  static final String MODULE = "BankAccount";

  < Account flavors, ranked by how guilty each one makes you feel. >
  < where money passes through, briefly >
  static final int TYPE_CHECKING = 0;
  < where money goes to be forgotten >
  static final int TYPE_SAVINGS  = 1;
  < where money you don't have lives >
  static final int TYPE_CREDIT   = 2;

  int loadedFlag;
  boolean isOpen;
  < whose signature is on the dotted line >
  String holder;
  < the institution with the marble lobby >
  String bankName;
  < 9-digit ABA number: Fed District + bank + checkdigit >
  String routingNumber;
  < the long one you can never remember >
  String accountNumber;
  < one of TYPE_* >
  int type;
  < the truth, in cents >
  int balanceCents;

  void load() {
    loadedFlag = 1;
    isOpen = false;
    holder = null;
    bankName = "First Bank of Sleela";
    routingNumber = "000000000";
    accountNumber = "0000000000";
    type = TYPE_CHECKING;
    balanceCents = 0;
  }
  boolean loaded() { return loadedFlag == 1; }
  String moduleName() { return MODULE; }

  < Open an account. Comes with a free pen on a chain you cannot steal. >
  void openFor(String accountHolder) {
    holder = accountHolder;
    isOpen = true;
    < Deterministic, obviously-fake demo numbers. 021 = NY Fed District. >
    routingNumber = "021000021";
    accountNumber = "1000000001";
    balanceCents = 0;
  }

  < Point the account at a specific bank + numbers (the grown-up setup). >
  void configure(String bank, String routing, String account, int acctType) {
    if (bank != null) { bankName = bank; }
    if (routing != null) { routingNumber = routing; }
    if (account != null) { accountNumber = account; }
    if (acctType >= TYPE_CHECKING && acctType <= TYPE_CREDIT) {
      type = acctType;
    }
  }

  < Money arrives. A rare and beautiful event. >
  void deposit(int cents) {
    if (cents > 0 && isOpen) { balanceCents = balanceCents + cents; }
  }

  < Money departs. Returns false if the account politely declines. >
  boolean withdraw(int cents) {
    if (!isOpen || cents <= 0) { return false; }
    if (type != TYPE_CREDIT && cents > balanceCents) { return false; }
    balanceCents = balanceCents - cents;
    return true;
  }

  < Close the account. The pen is yours to keep. It was always yours. >
  void close() {
    isOpen = false;
  }

  boolean open() { return isOpen; }
  int balance() { return balanceCents; }
  String routing() { return routingNumber; }
  String account() { return accountNumber; }
  String institution() { return bankName; }

  < The Federal Reserve District is encoded in the first two routing digits >
  < (01..12). This is how your checking account quietly knows its home office. >
  int fedDistrict() {
    if (routingNumber == null) { return 0; }
    < Lean on FederalReserveID so the mapping lives in exactly one place. >
    FederalReserveID fed = new FederalReserveID();
    fed.load();
    return fed.districtOfRouting(routingNumber);
  }

  String yn(boolean b) { if (b) { return "yes"; } return "no"; }

  String describe() {
    return MODULE + " bank=" + bankName + " routing=" + routingNumber
         + " acct=" + accountNumber + " balance=" + balanceCents
         + " open=" + yn(isOpen) + " district=" + fedDistrict();
  }
}