// Package path 提供了路径处理函数
package path

import (
	"fmt"
	"os"
	"path/filepath"
	"strings"
	"time"
)

// 获取银行采集本地 pdf 保存路径
func GetBankPdfPath(bank, taxNo, lsh string) string {
	dir := filepath.Join("./data/bank", bank, taxNo)
	_ = os.MkdirAll(dir, os.ModePerm)
	ts := time.Now().UnixNano()
	name := fmt.Sprintf("%s_%d.pdf", lsh, ts)
	return filepath.Join(dir, name)
}

// 获取错误截图路径
func GetErrImgPath(taxNo, period string) string {
	checkPath := filepath.Join("./data/sbImg", taxNo)
	_ = os.MkdirAll(checkPath, os.ModePerm)

	t := time.Now().Format("2006-01-02-15-04-05")
	name := fmt.Sprintf("%s-%s.png", period, t)
	return filepath.Join(checkPath, name)
}

// 去除文件扩展名 "x.pdf" -> "x"
func TrimExt(name string) string {
	ext := filepath.Ext(name)
	return strings.TrimSuffix(name, ext)
}
