-- name: GetConfig :one
SELECT * FROM config LIMIT 1;

-- name: UpsertConfig :exec
INSERT INTO config (api_token, zone_id, domain, update_period)
VALUES (?, ?, ?, ?)
ON CONFLICT DO UPDATE SET
    api_token = excluded.api_token,
    zone_id = excluded.zone_id,
    domain = excluded.domain,
    update_period = excluded.update_period;

-- name: DeleteAllConfig :exec
DELETE FROM config;

-- name: InsertConfig :exec
INSERT INTO config (api_token, zone_id, domain, update_period)
VALUES (?, ?, ?, ?);

-- name: InitSchema :exec
CREATE TABLE IF NOT EXISTS config (
    api_token TEXT NOT NULL DEFAULT '',
    zone_id TEXT NOT NULL DEFAULT '',
    domain TEXT NOT NULL DEFAULT 'mz.uy',
    update_period TEXT NOT NULL DEFAULT '0 */6 * * *'
);

-- Insert default config if none exists
INSERT OR IGNORE INTO config (api_token, zone_id, domain, update_period)
SELECT '', '', 'mz.uy', '0 */6 * * *'
WHERE NOT EXISTS (SELECT 1 FROM config);
