CREATE TABLE stores
(
    id                       uuid                                                         NOT NULL,
    name                     character varying        DEFAULT 'Bazaar'::character varying NOT NULL,
    default_currency_code    character varying        DEFAULT 'pln'::character varying    NOT NULL,
    swap_link_template       character varying,
    created_at               timestamp with time zone DEFAULT now()                       NOT NULL,
    updated_at               timestamp with time zone DEFAULT now()                       NOT NULL,
    metadata                 jsonb,
    payment_link_template    character varying,
    invite_link_template     character varying,
    default_sales_channel_id uuid,
    default_location_id      uuid
);

CREATE TABLE store_currencies
(
    store_id      uuid              NOT NULL,
    currency_code character varying NOT NULL
);

CREATE TABLE tax_providers
(
    id           uuid                 NOT NULL,
    is_installed boolean DEFAULT true NOT NULL
);

CREATE TABLE tax_rates
(
    id         uuid                                   NOT NULL,
    rate       real,
    code       character varying,
    name       character varying                      NOT NULL,
    region_id  uuid                                   NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL,
    metadata   jsonb
);

CREATE TABLE region_fulfillment_providers
(
    region_id   uuid NOT NULL,
    provider_id uuid NOT NULL
);

CREATE TABLE region_payment_providers
(
    region_id   uuid NOT NULL,
    provider_id uuid NOT NULL
);

CREATE TABLE regions
(
    id                 uuid                                   NOT NULL,
    name               character varying                      NOT NULL,
    currency_code      character varying                      NOT NULL,
    tax_rate           real                                   NOT NULL,
    tax_code           character varying,
    created_at         timestamp with time zone DEFAULT now() NOT NULL,
    updated_at         timestamp with time zone DEFAULT now() NOT NULL,
    deleted_at         timestamp with time zone,
    metadata           jsonb,
    gift_cards_taxable boolean                  DEFAULT true  NOT NULL,
    automatic_taxes    boolean                  DEFAULT true  NOT NULL,
    tax_provider_id    uuid
);

CREATE TABLE countries
(
    id           sequence          NOT NULL,
    iso_2        character varying NOT NULL,
    iso_3        character varying NOT NULL,
    num_code     integer           NOT NULL,
    name         character varying NOT NULL,
    display_name character varying NOT NULL,
    region_id    uuid
);

CREATE TABLE currencies
(
    code          character varying NOT NULL,
    symbol        character varying NOT NULL,
    symbol_native character varying NOT NULL,
    name          character varying NOT NULL
);
