package com.cool.store.utils;

import com.cool.store.enums.ExpenseSheetTypeEnum;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import static com.cool.store.utils.CoolDateUtils.DATE_FORMAT_SEC_9;

/**
 * <p>
 * 编号生成工具栏
 * </p>
 *
 * @author wangff
 * @since 2026/2/5
 */
public class GenerateNoUtil {


    private static final String ADJUSTMENT_ORDER_PREFIX = "TZ";
    private static final String EXPENSE_SHEET_PREFIX = "FY";
    private static final String SPLIT_ORDER_PREFIX = "FZ";

    /**
     * 生成编号，yyyyMMddHHmmssSSS+3位随机数
     */
    public static String generateMillsNoWithRandom() {
        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(DATE_FORMAT_SEC_9);
        return LocalDateTime.now().format(dateFormatter) + ((int) (Math.random() * 900) + 100);
    }

    /**
     * 单号
     * @param prefix
     * @return
     */
    public static String generateNo(String prefix) {
        return prefix + GenerateNoUtil.generateMillsNoWithRandom();
    }

    public static String generateAdjustmentNo(Integer expenseSheetType) {
        if (ExpenseSheetTypeEnum.ADJUSTMENT_SHEET.getCode().equals(expenseSheetType)){
            return ADJUSTMENT_ORDER_PREFIX + GenerateNoUtil.generateMillsNoWithRandom();
        }
        return EXPENSE_SHEET_PREFIX + GenerateNoUtil.generateMillsNoWithRandom();
    }

    public static  String generateSplitNo() {
        return SPLIT_ORDER_PREFIX + GenerateNoUtil.generateMillsNoWithRandom();
    }

}
