-- IT0 Shared Schema (public tenant management tables)
-- Run once on database initialization

CREATE SCHEMA IF NOT EXISTS it0_shared;

SET search_path TO it0_shared;

-- Tenants
CREATE TABLE IF NOT EXISTS tenants (
    id              VARCHAR(20) PRIMARY KEY,
    name            VARCHAR(200) NOT NULL,
    slug            VARCHAR(50) NOT NULL UNIQUE,
    plan            VARCHAR(20) NOT NULL DEFAULT 'free',
    owner_user_id   UUID NOT NULL,
    status          VARCHAR(20) NOT NULL DEFAULT 'active',
    max_servers     INTEGER NOT NULL DEFAULT 5,
    max_skills      INTEGER NOT NULL DEFAULT 10,
    max_users       INTEGER NOT NULL DEFAULT 3,
    max_sessions_per_day INTEGER NOT NULL DEFAULT 50,
    allowed_engines VARCHAR(20)[] NOT NULL DEFAULT '{claude_code_cli}',
    created_at      TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at      TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
