-- Create tables for configurable detail views

CREATE TABLE detail_views (
    id SERIAL,
    name VARCHAR(100) NOT NULL,
    config JSON DEFAULT NULL,
    tenant_id INTEGER DEFAULT NULL,
    branch_id INTEGER DEFAULT NULL,
    isDeleted BOOLEAN NOT NULL DEFAULT FALSE,
    updatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id)
);
CREATE INDEX detail_views_tenant_idx ON detail_views(tenant_id);
CREATE INDEX detail_views_branch_idx ON detail_views(branch_id);

CREATE TABLE detail_view_elements (
    id SERIAL,
    detail_view_id INTEGER NOT NULL,
    config JSON DEFAULT NULL,
    tenant_id INTEGER DEFAULT NULL,
    branch_id INTEGER DEFAULT NULL,
    order_index INTEGER DEFAULT NULL,
    isDeleted BOOLEAN NOT NULL DEFAULT FALSE,
    updatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id)
);
CREATE INDEX dve_view_idx ON detail_view_elements(detail_view_id);
CREATE INDEX dve_tenant_idx ON detail_view_elements(tenant_id);
CREATE INDEX dve_branch_idx ON detail_view_elements(branch_id);
