package com.njzscloud.common.sn.support;

import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.njzscloud.common.sn.SysIncSnService;
import com.njzscloud.common.sn.contant.PadMode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequiredArgsConstructor
public class IncSection implements ISnSection {

    private final String code;
    private final Integer step;
    private final Integer initialVal;
    private final PadMode padMode;
    private final String padVal;
    private final Integer padLen;
    private final SysIncSnService sysIncSnService = SpringUtil.getBean(SysIncSnService.class);

    @Override
    public String next() {
        Long val = sysIncSnService.inc(code);
        return padMode == PadMode.Zuo ? StrUtil.padPre(val.toString(), padLen, padVal) :
                padMode == PadMode.You ? StrUtil.padAfter(val.toString(), padLen, padVal) :
                        val.toString();
    }

}
