# The journey of one bill at Profitina Laundry Wiyung (O03), 30 Sep 2026 21:00.
# One block per step, blank line between blocks. A keyword fills the first
# 7 columns of a line; the rest of the line is its value. Keywords:
#   step   the use case and what happens      as     who performs the step
#   GET / POST <path>   the request ($name = a value saved by an earlier step)
#   body   JSON sent with a POST              expect the HTTP status we expect
#   show   a line to print; {a.b.0.c} reads the answer, {a.#} counts a list
#   save   name = path in the answer, kept for later steps

step   UC-01 Log in (main flow)
as     cashier Fitri, Wiyung
POST   /api/login
body   {"email": "kasir5@profitina-laundry.example",
body    "password": "Laundry#2026"}
expect 200
show   {employee.name}, {employee.role}, outlet {employee.outlet_id}

step   UC-02 Search customers by phone (main flow)
as     cashier Fitri, Wiyung
GET    /api/customers?q=0896%200000%201482
expect 200
show   {total} match: {data.0.id} {data.0.name}, {data.0.bills} bills so far
save   customer = data.0.id

step   UC-05 Create a bill, rack A01 (alternative 5a: rack in use)
as     cashier Fitri, Wiyung
POST   /api/bills
body   {"customer_id": "$customer", "service_id": "S0001", "unit": 5,
body    "rack": "A01"}
expect 422
show   {error.fields.rack}

step   UC-05 Create a bill, rack A03, down payment (main flow + 6a)
as     cashier Fitri, Wiyung
POST   /api/bills
body   {"customer_id": "$customer", "service_id": "S0001", "unit": 5,
body    "rack": "A03", "pay_now": {"method": "cash", "amount": 20000}}
expect 201
show   {id} {status}: {unit} x {service.price} = {payment}, paid {paid},
show     balance {balance}
show   rack {rack}, arrived {arrived}, promised {promised}
save   bill = id

step   UC-07 Hand over too early (alternative 1a)
as     cashier Fitri, Wiyung
POST   /api/bills/$bill/status
body   {"status": "departed"}
expect 409
show   {error.message}

step   UC-01 Log out
as     cashier Fitri, Wiyung
POST   /api/logout
expect 204

step   UC-01 Log in
as     washer Slamet, Wiyung
POST   /api/login
body   {"email": "cuci5@profitina-laundry.example",
body    "password": "Laundry#2026"}
expect 200
show   {employee.name}, {employee.role}, outlet {employee.outlet_id}

step   UC-06 Mark the bill finished (main flow)
as     washer Slamet, Wiyung
POST   /api/bills/$bill/status
body   {"status": "finished"}
expect 200
show   {id} {status} at {finished}, history has {history.#} rows

step   UC-06 Mark it finished again (alternative 3a)
as     washer Slamet, Wiyung
POST   /api/bills/$bill/status
body   {"status": "finished"}
expect 409
show   {error.message}

step   UC-09 A washer tries to take money (role check)
as     washer Slamet, Wiyung
POST   /api/bills/$bill/payments
body   {"method": "cash", "amount": 20000}
expect 403
show   {error.code}: {error.message}

step   UC-01 Log out
as     washer Slamet, Wiyung
POST   /api/logout
expect 204

step   UC-13 Check the status with bill id and phone (main flow)
as     customer Syaiful, on his phone, no login
GET    /api/status?bill=$bill&phone=0896%200000%201482
expect 200
show   {bill_id}: {status_text} since {finished}; {service}, {unit} units
show   total {payment}, still to pay {balance}; {outlet.name} {outlet.phone}

step   UC-13 The same bill with another phone (alternative 3a)
as     a stranger, no login
GET    /api/status?bill=$bill&phone=0812-0000-4710
expect 404
show   {error.message}

step   UC-01 Log in
as     cashier Fitri, Wiyung
POST   /api/login
body   {"email": "kasir5@profitina-laundry.example",
body    "password": "Laundry#2026"}
expect 200
show   {employee.name}, {employee.role}, outlet {employee.outlet_id}

step   UC-07 Hand over with an open balance (alternative 3b)
as     cashier Fitri, Wiyung
POST   /api/bills/$bill/status
body   {"status": "departed"}
expect 409
show   {error.message}

step   UC-09 Pay by QRIS without a reference (alternative 3b)
as     cashier Fitri, Wiyung
POST   /api/bills/$bill/payments
body   {"method": "qris", "amount": 20000}
expect 422
show   {error.fields.reference}

step   UC-09 Pay the balance by QRIS (main flow)
as     cashier Fitri, Wiyung
POST   /api/bills/$bill/payments
body   {"method": "qris", "amount": 20000,
body    "reference": "QRIS 512300774412"}
expect 201
show   payment {id}: {method} {amount} ({reference}); balance now {bill.balance}

step   UC-07 Hand over (main flow)
as     cashier Fitri, Wiyung
POST   /api/bills/$bill/status
body   {"status": "departed"}
expect 200
show   {id} {status} at {departed}, rack {rack} is free again

step   UC-14 Read the whole bill back
as     cashier Fitri, Wiyung
GET    /api/bills/$bill
expect 200
show   {id}: {payments.#} payments, paid {paid} of {payment}, balance {balance}
show   history: {history.0.status} ({history.0.employee.name}),
show     {history.1.status} ({history.1.employee.name}),
show     {history.2.status} ({history.2.employee.name})

step   UC-08 A cashier may not cancel (role check)
as     cashier Fitri, Wiyung
POST   /api/bills/B2944/cancel
expect 403
show   {error.code}: {error.message}

step   UC-01 Log out
as     cashier Fitri, Wiyung
POST   /api/logout
expect 204

step   UC-01 Log in
as     supervisor Bambang, Wiyung
POST   /api/login
body   {"email": "spv3@profitina-laundry.example",
body    "password": "Laundry#2026"}
expect 200
show   {employee.name}, {employee.role}, outlet {employee.outlet_id}

step   UC-08 Cancel a bill that has a down payment (alternative 1a)
as     supervisor Bambang, Wiyung
POST   /api/bills/B2952/cancel
expect 409
show   {error.message}

step   UC-08 Cancel a queued bill without payments (main flow)
as     supervisor Bambang, Wiyung
POST   /api/bills/B2944/cancel
expect 200
show   {id} {status}, cancelled={cancelled}, payment {payment},
show     last event {history.1.status}

step   UC-15 Record a complaint on the collected bill (main flow)
as     supervisor Bambang, Wiyung
POST   /api/bills/$bill/complaint
expect 201
show   {status} at {changed_at} by {employee.name}

step   UC-01 Log out
as     supervisor Bambang, Wiyung
POST   /api/logout
expect 204
