// A SEPA QR code for an invoice ("GiroCode"): printed on the paper, a banking app scans it and
// the transfer is filled in. Built, read back, and refused where a bank's app would refuse it.
//
//   quillo run epc_qr.qwe      then open http://localhost:8080/payload, /code.svg, /read and /refused

use "epc_qr.qwer"

let INVOICE = {
    name: "Red Cross of Belgium",
    iban: "BE72 0000 0000 1616",
    bic: "BPOTBEB1",
    amount: "1.00",
    purpose: "CHAR",
    text: "Urgency fund",
}

route GET /payload = respond(200, epc_qr_build(INVOICE)?, { "content-type": "text/plain" })

route GET /code.svg = respond(200, epc_qr_svg(epc_qr_build(INVOICE)?, 300)?, { "content-type": "image/svg+xml" })

route GET /read = epc_qr_parse(epc_qr_build(merge(INVOICE, { text: null, reference: "RF18539007547034", amount: 12.5 }))?)?

// The guideline's own example, with CRLF line ends and version 001.
route GET /guideline = epc_qr_parse("BCD\r\n001\r\n1\r\nSCT\r\nBPOTBEB1\r\nRed Cross of Belgium\r\nBE72000000001616\r\nEUR1\r\nCHAR\r\n\r\nUrgency fund\r\nSample QR code")?

route GET /refused = {
    iban: epc_qr_build(merge(INVOICE, { iban: "BE72000000001617" })).error,
    country: epc_qr_build(merge(INVOICE, { iban: "US64SVBKUS6S3300958879" })).error,
    decimals: epc_qr_build(merge(INVOICE, { amount: "1.005" })).error,
    zero: epc_qr_build(merge(INVOICE, { amount: "0" })).error,
    both: epc_qr_build(merge(INVOICE, { reference: "RF18539007547034" })).error,
    reference: epc_qr_build(merge(INVOICE, { text: null, reference: "RF19539007547034" })).error,
    no_bic: epc_qr_build(merge(INVOICE, { version: "001", bic: null })).error,
    not_one: epc_qr_parse("hello").error,
    usd: epc_qr_parse("BCD\n002\n1\nSCT\n\nX\nBE72000000001616\nUSD5.00").error,
}
