-- 创建用户投诉表 (PostgreSQL兼容)
CREATE TABLE IF NOT EXISTS user_complaint (
    id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    user_id BIGINT NOT NULL,
    title VARCHAR(200) NOT NULL,
    content VARCHAR(1000) NOT NULL,
    complainant VARCHAR(100),
    status VARCHAR(20) DEFAULT '待处理',
    handler_id BIGINT,
    handle_result VARCHAR(500),
    handled_at TIMESTAMP NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- 添加注释 (PostgreSQL方式)
COMMENT ON COLUMN user_complaint.id IS '主键ID';
COMMENT ON COLUMN user_complaint.user_id IS '被投诉用户ID';
COMMENT ON COLUMN user_complaint.title IS '投诉标题';
COMMENT ON COLUMN user_complaint.content IS '投诉内容';
COMMENT ON COLUMN user_complaint.complainant IS '投诉人';
COMMENT ON COLUMN user_complaint.status IS '处理状态：待处理/处理中/已处理/已关闭';
COMMENT ON COLUMN user_complaint.handler_id IS '处理人ID';
COMMENT ON COLUMN user_complaint.handle_result IS '处理结果';
COMMENT ON COLUMN user_complaint.handled_at IS '处理时间';
COMMENT ON COLUMN user_complaint.created_at IS '创建时间';

-- 添加索引
CREATE INDEX IF NOT EXISTS idx_user_complaint_user_id ON user_complaint(user_id);
CREATE INDEX IF NOT EXISTS idx_user_complaint_status ON user_complaint(status);
CREATE INDEX IF NOT EXISTS idx_user_complaint_created_at ON user_complaint(created_at);
