\ir init_l0.sql
\ir init_l1.sql
\ir init_l2.sql
\ir init_l3.sql
\ir init_l4.sql

-- duas contas com saldo inicial 100.0
select
	--	l0.cria_conta(id, saldo_inicial, comentario), -- conta criada no primeiro uso
		l1.cria_conta(id, saldo_inicial, comentario),
		l2.cria_conta(id, saldo_inicial, comentario),
		l3.cria_conta(id, saldo_inicial, comentario),
		l4.cria_conta(id, saldo_inicial, comentario)
	from (values (1::bigint, 100::numeric, 'a'::text), (2, 100, 'b')) as _(id, saldo_inicial, comentario);

-- inspeciona estado inicial
select l1.consulta_saldo(i), l2.consulta_saldo(i), l3.consulta_saldo(i), l4.consulta_saldo(i) from generate_series(1,2) as i;
table l1.account;
table l2.account;
table l3.account;
table l4.account;
table l2.account_balance;
table l3.account_balance;
table l4.account_balance;
table l1.transaction;
table l2.transaction;
table l3.transaction;
table l4.transaction;
table l1.entry;
table l2.entry;
table l3.entry;
table l4.transaction;

-- transfere valor entre contas
select l1.transfere_valor(1, 2, 10, 'dez');
select l2.transfere_valor(1, 2, 10, 'dez');
select l3.transfere_valor(1, 2, 10, 'dez');
select l4.transfere_valor(1, 2, 10, 'dez');

-- inspeciona novo estado
select l1.consulta_saldo(i), l2.consulta_saldo(i), l3.consulta_saldo(i), l4.consulta_saldo(i) from generate_series(1,2) as i;
table l1.account;
table l2.account;
table l3.account;
table l4.account;
table l2.account_balance;
table l3.account_balance;
table l4.account_balance;
table l1.transaction;
table l2.transaction;
table l3.transaction;
table l4.transaction;
table l1.entry;
table l2.entry;
table l3.entry;
table l4.transaction;

-- transfere vários valores entre contas
select l1.transfere_valor(1, 2, 5); select l2.transfere_valor(1, 2, 5); select l3.transfere_valor(1, 2, 5); select l4.transfere_valor(1, 2, 5);
select l1.transfere_valor(1, 2, 6); select l2.transfere_valor(1, 2, 6); select l3.transfere_valor(1, 2, 6); select l4.transfere_valor(1, 2, 6);
select l1.transfere_valor(1, 2, 7); select l2.transfere_valor(1, 2, 7); select l3.transfere_valor(1, 2, 7); select l4.transfere_valor(1, 2, 7);
select l1.transfere_valor(1, 2, 5); select l2.transfere_valor(1, 2, 5); select l3.transfere_valor(1, 2, 5); select l4.transfere_valor(1, 2, 5);
select l1.transfere_valor(1, 2, 2); select l2.transfere_valor(1, 2, 2); select l3.transfere_valor(1, 2, 2); select l4.transfere_valor(1, 2, 2);
select l1.transfere_valor(1, 2, 4); select l2.transfere_valor(1, 2, 4); select l3.transfere_valor(1, 2, 4); select l4.transfere_valor(1, 2, 4);
select l1.transfere_valor(1, 2, 2); select l2.transfere_valor(1, 2, 2); select l3.transfere_valor(1, 2, 2); select l4.transfere_valor(1, 2, 2);
select l1.transfere_valor(2, 1, 9); select l2.transfere_valor(2, 1, 9); select l3.transfere_valor(2, 1, 9); select l4.transfere_valor(2, 1, 9);
select l1.transfere_valor(2, 1, 7); select l2.transfere_valor(2, 1, 7); select l3.transfere_valor(2, 1, 7); select l4.transfere_valor(2, 1, 7);
select l1.transfere_valor(2, 1, 5); select l2.transfere_valor(2, 1, 5); select l3.transfere_valor(2, 1, 5); select l4.transfere_valor(2, 1, 5);
select l1.transfere_valor(2, 1, 3); select l2.transfere_valor(2, 1, 3); select l3.transfere_valor(2, 1, 3); select l4.transfere_valor(2, 1, 3);

-- inspeciona novo estado
select l1.consulta_saldo(i), l2.consulta_saldo(i), l3.consulta_saldo(i), l4.consulta_saldo(i) from generate_series(1,2) as i;
table l1.account;
table l2.account;
table l3.account;
table l4.account;
table l2.account_balance;
table l3.account_balance;
table l4.account_balance;
table l1.transaction;
table l2.transaction;
table l3.transaction;
table l4.transaction;
table l1.entry;
table l2.entry;
table l3.entry;
table l4.transaction;

analyze;
