import { get } from '@/utils/http.js';
import { getInfo } from '@/utils/auth.js';

export async function getNumber(type) {
    const keys = {
        'record': 'job.result.record-file.id',
        'immediately': 'job.result.immediately_file_id',
        'deadline': 'job.result.deadline_file_id'
    };
    const year = new Date().getFullYear();
    let res = ['〔', year, '〕', '第'];
    const key = keys[type];
    const num = await get(`/v2/api/sys_properties/increase?properties_key=${key}`);
    if (num && num.properties_value) {
        res.push(formatNumber(num.properties_value));
        res.push('号');
    }
    if (type == 'record') {
        return res;
    }

    const user = getInfo();
    if (user && user.enforce_org_id) {
        const org = await get(`/v2/api/enforce_organize?query=enforce_org_id==${user.enforce_org_id}`);
        if (org && org.data && org.data.length > 0) {
            const list = [org.data[0].short_name, '消', type == 'deadline' ? '限字' : '即字'];
            // res = org.data[0].short_name + (type == 'deadline' ? '消限字' : '消即字') + res;
            res = [...list, ...res];
        }
    }
    return res;
}

function formatNumber(num) {
    return num;//(Array(4).join('0') + num).slice(-4);
}