package com.ycwl.basic.profitsharing.mapper;

import com.ycwl.basic.profitsharing.entity.ProfitSharingUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProfitSharingUserMapper {
    @Insert("INSERT INTO profit_sharing_user (config_id, name, description, wx_rate, real_rate, rate_mode) " +
            "VALUES (#{configId}, #{name}, #{description}, #{wxRate}, #{realRate}, #{rateMode})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(ProfitSharingUser user);

    @Update("UPDATE profit_sharing_user SET config_id = #{configId}, " +
            "name = #{name}, description = #{description}, wx_rate = #{wxRate}, real_rate = #{realRate}, rate_mode = #{rateMode} WHERE id = #{id}")
    void update(ProfitSharingUser user);

    @Update("UPDATE profit_sharing_user SET wx_pay_type = #{wxPayType}, wx_pay_config = #{wxPayConfig} WHERE id = #{id}")
    void updateWxPayConfig(ProfitSharingUser user);

    @Delete("DELETE FROM profit_sharing_user WHERE id = #{id}")
    void deleteById(Long id);

    @Delete("DELETE FROM profit_sharing_user WHERE config_id = #{configId}")
    void deleteByConfigId(Long configId);

    @Select("SELECT * FROM profit_sharing_user WHERE id = #{id}")
    ProfitSharingUser findById(Long id);

    @Select("SELECT * FROM profit_sharing_user")
    List<ProfitSharingUser> findAll();

    // 新增: 根据configId查询所有记录
    @Select("SELECT * FROM profit_sharing_user WHERE config_id = #{configId}")
    List<ProfitSharingUser> findByConfigId(Long configId);
}