package com.ankurm.lg4j;
import org.bsc.langgraph4j.state.AgentState;
import org.bsc.langgraph4j.state.Channel;
import org.bsc.langgraph4j.state.Channels;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* The shared state every node reads and writes.
*
*
State is just a {@code Map} with typed accessors. A key with an
* appender channel ({@code trail}) accumulates values; any other key is
* overwritten by the latest node that writes it.
*/
public class LoanState extends AgentState {
public static final String APPLICANT = "applicant";
public static final String AMOUNT = "amount";
public static final String INCOME = "income";
public static final String CREDIT_SCORE = "creditScore";
public static final String RISK = "risk";
public static final String DECISION = "decision";
public static final String TRAIL = "trail";
/** Channel schema: {@code trail} appends, everything else replaces. */
public static final Map> SCHEMA =
Map.of(TRAIL, Channels.appender(ArrayList::new));
public LoanState(Map data) {
super(data);
}
public String applicant() { return this.value(APPLICANT).orElse("?"); }
public int amount() { return this.value(AMOUNT).orElse(0); }
public int income() { return this.value(INCOME).orElse(0); }
public int creditScore() { return this.value(CREDIT_SCORE).orElse(0); }
public String risk() { return this.value(RISK).orElse("UNKNOWN"); }
public String decision() { return this.value(DECISION).orElse("PENDING"); }
public List trail() { return this.>value(TRAIL).orElse(List.of()); }
}