-- Create roles table and modal

CREATE TABLE roles (
    id SERIAL,
    name varchar(100) NOT NULL,
    description text DEFAULT NULL,
    tenant_id INTEGER DEFAULT NULL,
    branch_id INTEGER DEFAULT NULL,
    created_by INTEGER DEFAULT NULL,
    isDeleted BOOLEAN NOT NULL DEFAULT FALSE,
    updatedAt timestamp NOT NULL DEFAULT current_timestamp,
    PRIMARY KEY (id)
);
CREATE INDEX roles_tenant_idx ON roles (tenant_id);
CREATE INDEX roles_branch_idx ON roles (branch_id);

INSERT INTO ui_modals (name, config, tenant_id, branch_id)
SELECT 'Roles', '{"title":"Roles","body":[{"type":"table","options":{"tableName":"roles","showGlobalSearch":false}}],"footer":[{"type":"button","label":"Close","onClick":"closeModal"}]}' , NULL, NULL
WHERE NOT EXISTS (SELECT 1 FROM ui_modals WHERE name = 'Roles');
