-- Parsed model pricing and mapping tables
CREATE TABLE IF NOT EXISTS aigcspace.parsed_model_pricing (
    id SERIAL PRIMARY KEY,
    model_code VARCHAR(120) NOT NULL UNIQUE,
    payload JSONB NOT NULL,
    source_file VARCHAR(255),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX IF NOT EXISTS idx_parsed_model_pricing_model_code ON aigcspace.parsed_model_pricing(model_code);

COMMENT ON TABLE aigcspace.parsed_model_pricing IS '解析后的模型定价信息（parsed_json 入库）';
COMMENT ON COLUMN aigcspace.parsed_model_pricing.payload IS '原始解析JSON内容';

CREATE TABLE IF NOT EXISTS aigcspace.parsed_model_mapping (
    id SERIAL PRIMARY KEY,
    source_key VARCHAR(200) NOT NULL UNIQUE,
    normalized_key VARCHAR(200) NOT NULL UNIQUE,
    model_code VARCHAR(120) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX IF NOT EXISTS idx_parsed_model_mapping_source_key ON aigcspace.parsed_model_mapping(source_key);
CREATE INDEX IF NOT EXISTS idx_parsed_model_mapping_normalized_key ON aigcspace.parsed_model_mapping(normalized_key);
CREATE INDEX IF NOT EXISTS idx_parsed_model_mapping_model_code ON aigcspace.parsed_model_mapping(model_code);

COMMENT ON TABLE aigcspace.parsed_model_mapping IS '模型名称/别名到model_code的映射（map.json 入库）';
COMMENT ON COLUMN aigcspace.parsed_model_mapping.source_key IS '原始映射键';
COMMENT ON COLUMN aigcspace.parsed_model_mapping.normalized_key IS '归一化后的映射键';
COMMENT ON COLUMN aigcspace.parsed_model_mapping.model_code IS '对应的模型代码';
