-- DDL generated by Hibernate 7.4.13.Final for H2, strategy SINGLE_TABLE
-- tables created: 2


    create sequence st_order_seq start with 1 increment by 50;

    create sequence st_payment_seq start with 1 increment by 50;

    create table st_order (
        id bigint not null,
        payment_id bigint not null,
        reference varchar(20) not null,
        primary key (id)
    );

    create table st_payment (
        amount numeric(12,2) not null,
        card_last4 varchar(4),
        currency varchar(3) not null,
        id bigint not null,
        bank_code varchar(11),
        payment_type varchar(12) not null check ((payment_type in ('CARD','BANK','WALLET'))),
        network varchar(16),
        provider varchar(24),
        iban varchar(34),
        primary key (id),
        constraint st_payment_subclass_columns check ((payment_type <> 'CARD' or card_last4 is not null) and (payment_type <> 'BANK' or iban is not null) and (payment_type <> 'WALLET' or provider is not null))
    );

    alter table if exists st_order 
       add constraint FKdi3y406uyk3cm6po29lmjirt5 
       foreign key (payment_id) 
       references st_payment;
