-- SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
--
-- SPDX-License-Identifier: AGPL-3.0-or-later

CREATE TABLE IF NOT EXISTS cqrs_billing_bill_query
(
    version           bigint CHECK (version >= 0) NOT NULL,

    created_time timestamp with time zone DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
	bill_id UUID NOT NULL UNIQUE,


	store_id UUID NOT NULL,
	token_number INTEGER NOT NULL,

    total_price_minor INTEGER DEFAULT NULL,
    total_price_major INTEGER DEFAULT NULL,
    total_price_currency TEXT DEFAULT NULL,

	deleted BOOLEAN NOT NULL DEFAULT FALSE,

    PRIMARY KEY (bill_id)
);

CREATE TABLE IF NOT EXISTS cqrs_billing_bill_next_token_id
(
	store_id UUID NOT NULL,
	token_number INTEGER NOT NULL DEFAULT 1,

    PRIMARY KEY (store_id)
);
