package com.clx.performance.service.impl.settle;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.clx.performance.component.IdGenerateSnowFlake;
import com.clx.performance.dao.settle.NetworkDriverAccountDao;
import com.clx.performance.model.settle.NetworkDriverAccount;
import com.clx.performance.param.pc.PageNetworkAccountListParam;
import com.clx.performance.param.pc.driver.NetworkDriverAccountParam;
import com.clx.performance.service.settle.NetworkDriverAccountService;
import com.clx.performance.vo.pc.NetworkDriverAccountVO;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @author kavin
 * Date 2023-12-19
 * Time 11:34
 */
@Service
@AllArgsConstructor
public class NetworkDriverAccountServiceImpl implements NetworkDriverAccountService {

    private final NetworkDriverAccountDao networkDriverAccountDao;

    private final IdGenerateSnowFlake idGenerateSnowFlake;

    @Override
    public IPage<NetworkDriverAccountVO> networkAccountList(PageNetworkAccountListParam param) {
        return networkDriverAccountDao.networkAccountList(param);
    }

    @Override
    public void createNetworkDriverAccount(NetworkDriverAccountParam param) {
        String walletCode = idGenerateSnowFlake.nextIdToString(1L);
        NetworkDriverAccount entity = NetworkDriverAccount.builder().driverUserNo(param.getDriverUserNo())
                .driverUserName(param.getDriverUserName())
                .accountBalance(BigDecimal.ZERO)
                .usableBalance(BigDecimal.ZERO)
                .frozenBalance(BigDecimal.ZERO)
                .createBy("系统")
                .walletCode(walletCode).build();
        networkDriverAccountDao.saveEntity(entity);
    }
}
