-- Label designer: printable labels for paper QSL work.
--
-- Two tables because the two things have different lifetimes. A STOCK is the
-- physical roll in the printer (width, height, margins) — one per label size,
-- shared by every design printed on it. A TEMPLATE is one design (what goes on
-- the label) and points at the stock it was drawn for. Deleting a design must
-- never take the roll definition of the other designs with it.
--
-- kind separates the two families the operator designs: 'qso' (the label glued
-- on the QSL card, with its repeating QSO table) and 'address' (destination or
-- return address). is_default is per (kind, profile scope) — printing wants
-- "the QSO label" and "the address label" without asking every time.
CREATE TABLE label_stocks (
    id          INTEGER PRIMARY KEY,
    name        TEXT NOT NULL,
    json        TEXT NOT NULL,
    created_at  TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
    updated_at  TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
);
CREATE TABLE label_templates (
    id          INTEGER PRIMARY KEY,
    name        TEXT NOT NULL,
    kind        TEXT NOT NULL,
    profile_id  INTEGER REFERENCES station_profiles(id) ON DELETE SET NULL,
    stock_id    INTEGER REFERENCES label_stocks(id) ON DELETE SET NULL,
    json        TEXT NOT NULL,
    is_default  INTEGER NOT NULL DEFAULT 0,
    created_at  TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
    updated_at  TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
);
