package com.qnfhq.modules.c2c.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qnfhq.common.service.impl.CrudServiceImpl;
import com.qnfhq.modules.c2c.dao.AppAssetLogDao;
import com.qnfhq.modules.c2c.dto.AppAssetLogDTO;
import com.qnfhq.modules.c2c.entity.AppAssetLogEntity;
import com.qnfhq.modules.c2c.service.AppAssetLogService;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

/**
 * c2c用户资产变动日志
 *
 * @author yelz 30262728@qq.com
 * @since 1.0.0 2025-11-19
 */
@Service
public class AppAssetLogServiceImpl extends CrudServiceImpl<AppAssetLogDao, AppAssetLogEntity, AppAssetLogDTO> implements AppAssetLogService {

    @Override
    public QueryWrapper<AppAssetLogEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<AppAssetLogEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public boolean insertAssetLog(Long orderId, Long userId, String symbol, Integer type,
                              BigDecimal beforeAmount, BigDecimal afterAmount,
                              BigDecimal beforeAvail, BigDecimal afterAvail,
                              BigDecimal beforeFrozen, BigDecimal afterFrozen,
                              String remark) {
        AppAssetLogEntity appAssetLogEntity = new AppAssetLogEntity();
        appAssetLogEntity.setOrderId(orderId);
        appAssetLogEntity.setUserId(userId);
        appAssetLogEntity.setSymbol(symbol);
        appAssetLogEntity.setType(type);
        appAssetLogEntity.setBeforeTotal(beforeAmount);
        appAssetLogEntity.setAfterTotal(afterAmount);
        appAssetLogEntity.setBeforeAvailable(beforeAvail);
        appAssetLogEntity.setAfterAvailable(afterAvail);
        appAssetLogEntity.setBeforeFrozen(beforeFrozen);
        appAssetLogEntity.setAfterFrozen(afterFrozen);
        appAssetLogEntity.setRemark(remark);
        appAssetLogEntity.setCreateTime(new Date());
        return insert(appAssetLogEntity);
    }
}