CREATE TABLE public.janus_providers
(
    id           bigint         NOT NULL,
    name         varchar(100)   NULL,
    base_url     varchar(255)   NULL,
    status       int4 DEFAULT 0 NULL,
    created_at   bigint         NOT NULL,
    created_time timestamp      NOT NULL,
    updated_at   bigint         NULL,
    updated_time timestamp      NULL,
    del_flag     int4 DEFAULT 0 NOT NULL,
    CONSTRAINT janus_providers_pk PRIMARY KEY (id)
);
COMMENT ON TABLE public.janus_providers IS 'AI 服务供应商（OpenAI、Anthropic、Azure 等）';

COMMENT ON COLUMN public.janus_providers.id IS '主键ID';
COMMENT ON COLUMN public.janus_providers.name IS '服务供应商名称';
COMMENT ON COLUMN public.janus_providers.base_url IS '服务地址';
COMMENT ON COLUMN public.janus_providers.status IS '服务状态（1=启用，0=停用）';
COMMENT ON COLUMN public.janus_providers.created_at IS '创建者';
COMMENT ON COLUMN public.janus_providers.created_time IS '创建时间';
COMMENT ON COLUMN public.janus_providers.updated_at IS '修改者';
COMMENT ON COLUMN public.janus_providers.updated_time IS '修改时间';
COMMENT ON COLUMN public.janus_providers.del_flag IS '删除标志（1=已删除，0=未删除）';

CREATE TABLE public.janus_models
(
    id           bigint         NOT NULL,
    provider_id  bigint         NOT NULL,
    name         varchar        not null,
    model_type   varchar        not null,
    status       int4 default 0 not null,
    created_at   bigint         NOT NULL,
    created_time timestamp      NOT NULL,
    updated_at   bigint         NULL,
    updated_time timestamp      NULL,
    del_flag     int4 DEFAULT 0 NOT NULL,
    CONSTRAINT janus_models_pk PRIMARY KEY (id)
);
COMMENT ON TABLE public.janus_models IS '供应商下可用的AI模型';

COMMENT ON COLUMN public.janus_models.id IS '主键ID';
COMMENT ON COLUMN public.janus_models.provider_id IS '供应商ID';
COMMENT ON COLUMN public.janus_models.name IS '模型名称';
COMMENT ON COLUMN public.janus_models.model_type IS '模型类型(chat/completion/embedding/image)';
COMMENT ON COLUMN public.janus_models.status IS '模型状态（1=启用，0=停用）';
COMMENT ON COLUMN public.janus_models.created_at IS '创建者';
COMMENT ON COLUMN public.janus_models.created_time IS '创建时间';
COMMENT ON COLUMN public.janus_models.updated_at IS '修改者';
COMMENT ON COLUMN public.janus_models.updated_time IS '修改时间';
COMMENT ON COLUMN public.janus_models.del_flag IS '删除标志（1=已删除，0=未删除）';

CREATE TABLE public.janus_channels
(
    id           bigint          NOT NULL,
    name         varchar         NOT NULL,
    provider_id  bigint          NOT NULL,
    model_id     bigint          NULL,
    weight       int4 DEFAULT 1  NOT NULL,
    priority     int4 DEFAULT 1  NOT NULL,
    rate_limit   int4 DEFAULT 60 NOT NULL,
    status       int4 DEFAULT 0  NULL,
    created_at   bigint          NOT NULL,
    created_time timestamp       NOT NULL,
    updated_at   bigint          NULL,
    updated_time timestamp       NULL,
    del_flag     int4 DEFAULT 0  NOT NULL,
    CONSTRAINT janus_channels_pk PRIMARY KEY (id)
);
COMMENT ON TABLE public.janus_channels IS '路由转发通道（连接供应商和模型，支持权重和优先级）';

COMMENT ON COLUMN public.janus_channels.id IS '主键ID';
COMMENT ON COLUMN public.janus_channels.name IS '通道名称';
COMMENT ON COLUMN public.janus_channels.provider_id IS '供应商ID';
COMMENT ON COLUMN public.janus_channels.model_id IS '模型ID（NULL表示供应商级别通道）';
COMMENT ON COLUMN public.janus_channels.weight IS '负载均衡权重';
COMMENT ON COLUMN public.janus_channels.priority IS '优先级（数字越小越高）';
COMMENT ON COLUMN public.janus_channels.rate_limit IS '每分钟请求数上限';
COMMENT ON COLUMN public.janus_channels.status IS '通道状态（1=启用，0=停用）';
COMMENT ON COLUMN public.janus_channels.created_at IS '创建者';
COMMENT ON COLUMN public.janus_channels.created_time IS '创建时间';
COMMENT ON COLUMN public.janus_channels.updated_at IS '修改者';
COMMENT ON COLUMN public.janus_channels.updated_time IS '修改时间';
COMMENT ON COLUMN public.janus_channels.del_flag IS '删除标志（1=已删除，0=未删除）';

CREATE TABLE public.janus_api_keys
(
    id           bigint          NOT NULL,
    key          varchar         NOT NULL,
    name         varchar         NOT NULL,
    rate_limit   int4 DEFAULT 60 NOT NULL,
    status       int4 DEFAULT 0  NULL,
    expired_at   timestamp       NULL,
    created_at   bigint          NOT NULL,
    created_time timestamp       NOT NULL,
    updated_at   bigint          NULL,
    updated_time timestamp       NULL,
    del_flag     int4 DEFAULT 0  NOT NULL,
    CONSTRAINT janus_api_keys_pk PRIMARY KEY (id)
);
COMMENT ON TABLE public.janus_api_keys IS '调用方认证密钥';

COMMENT ON COLUMN public.janus_api_keys.id IS '主键ID';
COMMENT ON COLUMN public.janus_api_keys.key IS 'API密钥字符串';
COMMENT ON COLUMN public.janus_api_keys.name IS '密钥名称/用途描述';
COMMENT ON COLUMN public.janus_api_keys.rate_limit IS '每分钟请求数上限';
COMMENT ON COLUMN public.janus_api_keys.status IS '密钥状态（1=启用，0=停用）';
COMMENT ON COLUMN public.janus_api_keys.expired_at IS '过期时间（NULL=永不过期）';
COMMENT ON COLUMN public.janus_api_keys.created_at IS '创建者';
COMMENT ON COLUMN public.janus_api_keys.created_time IS '创建时间';
COMMENT ON COLUMN public.janus_api_keys.updated_at IS '修改者';
COMMENT ON COLUMN public.janus_api_keys.updated_time IS '修改时间';
COMMENT ON COLUMN public.janus_api_keys.del_flag IS '删除标志（1=已删除，0=未删除）'