<cfsetting showdebugoutput="false">
<cfsetting enablecfoutputonly="true">
<cfcontent type="application/json; charset=utf-8" reset="true">
<cfheader name="Cache-Control" value="max-age=3600">

<cfscript>
/**
 * Get list of address types
 * GET: /api/addresses/types.cfm
 * Returns: { OK: true, TYPES: [{ ID: 1, Label: "Billing" }, ...] }
 */

try {
    qTypes = queryTimed("
        SELECT tt_AddressTypeID as ID, tt_AddressType as Label
        FROM tt_AddressTypes
        ORDER BY tt_AddressTypeID
    ", {}, { datasource: "payfrit" });

    types = [];
    for (row in qTypes) {
        arrayAppend(types, {
            "ID": row.ID,
            "Label": row.Label
        });
    }

    writeOutput(serializeJSON({
        "OK": true,
        "TYPES": types
    }));

} catch (any e) {
    writeOutput(serializeJSON({
        "OK": false,
        "ERROR": "server_error",
        "MESSAGE": e.message
    }));
}
</cfscript>
