// A person in a ledger
export interface Person {
  id: string;        // UUID
  name: string;
}

// An expense paid by one person, split among several
// Mutable: we may need to update the amount and splitAmong fields
export interface Expense {
  id: string;                // UUID
  ledgerId: string;          // LedgerMeta.id
  paidBy: string;           // Person.id
  amount: number;           // In cents (integer)
  description: string;
  splitAmong: string[];     // Person.id[] — who this expense is split among
  createdAt: string;        // ISO 8601
}

// A direct transfer between two people
// Immutable: once a transfer has happened in the real world it cannot be undone
// If a transfer was added with incorrect fields (e.g.: amount) the user should delete it and add a new one
export interface Transfer {
  id: string;                // UUID
  ledgerId: string;
  from: string;              // Person.id
  to: string;                // Person.id
  amount: number;            // In cents
  createdAt: string;         // ISO 8601
}

// A computed settlement payment (output of the min-cash-flow algorithm)
// No id or ledgerId because this is ephemeral local data; the output of min-cash-flow which may prompt the user to upload a new Transfer
export interface Settlement {
  from: string;              // Person.id
  to: string;                // Person.id
  amount: number;            // In cents
}

// The encrypted ledger payload stored on the server
export interface LedgerData {
  people: Person[];
  expenses: Expense[];
  transfers: Transfer[];
}

// Ledger metadata (unencrypted, stored alongside ciphertext)
export interface LedgerMeta {
  id: string;                // UUID
  name: string;
  createdAt: string;         // ISO 8601
  updatedAt: string;         // ISO 8601
}
