package com.dora.mapper;

import com.dora.entity.PlazaWorkReportLimit;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;

/**
 * 广场作品投诉限制 Mapper
 * 
 * @author 1818AI
 * @since 2025-11-14
 */
@Mapper
public interface PlazaWorkReportLimitMapper {
    
    /**
     * 插入或更新投诉限制记录
     */
    @Insert("INSERT INTO plaza_work_report_limit (user_id, report_count, last_report_time, reset_date, create_time, update_time) " +
            "VALUES (#{userId}, #{reportCount}, #{lastReportTime}, #{resetDate}, NOW(), NOW()) " +
            "ON DUPLICATE KEY UPDATE " +
            "report_count = VALUES(report_count), " +
            "last_report_time = VALUES(last_report_time), " +
            "reset_date = VALUES(reset_date), " +
            "update_time = NOW()")
    int insertOrUpdate(PlazaWorkReportLimit limit);
    
    /**
     * 根据用户ID查询
     */
    @Select("SELECT * FROM plaza_work_report_limit WHERE user_id = #{userId}")
    PlazaWorkReportLimit findByUserId(Long userId);
    
    /**
     * 重置用户投诉计数（每日重置）
     */
    @Update("UPDATE plaza_work_report_limit SET " +
            "report_count = 0, " +
            "reset_date = #{resetDate}, " +
            "update_time = NOW() " +
            "WHERE user_id = #{userId}")
    int resetReportCount(@Param("userId") Long userId, @Param("resetDate") LocalDate resetDate);
    
    /**
     * 增加投诉计数
     */
    @Update("UPDATE plaza_work_report_limit SET " +
            "report_count = report_count + 1, " +
            "last_report_time = NOW(), " +
            "update_time = NOW() " +
            "WHERE user_id = #{userId}")
    int incrementReportCount(Long userId);
}

