import { nanoid } from '../nanoid.js';
import uuidV4 from '../lib/uuid.js';
export const noValue = Symbol('noValue');
/**
 * A class to be used for generating values from pre-defined functions.
 * This is used to provide default values for data properties based on specified functions.
 */
export class DataValueGenerator {
    /**
     * The current value for the `number.incremental` function.
     * This counter is incremented each time an incremental number is generated.
     */
    increment = 0;
    /**
     * A symbol representing the absence of a value.
     * Used as a return value when a function cannot generate a value of the requested type.
     */
    static noValue = noValue;
    /**
     * Generates a value based on the provided function name and data type.
     * @param fn The name of the function to use for value generation (e.g., 'random', 'uuid-v4', 'incremental').
     * @param type The data type of the value to generate (e.g., 'string', 'number', 'date', 'time', 'datetime').
     * @returns The generated value, or the `noValue` symbol if the function or type is not supported.
     */
    generate(fn, type) {
        if (type === 'string') {
            return this.generateString(fn);
        }
        if (type === 'number') {
            return this.generateNumber(fn);
        }
        if (type === 'date') {
            return this.generateDate(fn);
        }
        if (type === 'time') {
            return this.generateTime(fn);
        }
        if (type === 'datetime') {
            return this.generateDateTime(fn);
        }
        return noValue;
    }
    /**
     * Generates a string value based on the function name.
     * @param fn The name of the string generation function.
     * @returns The generated string value, or `noValue` if the function is not supported.
     */
    generateString(fn) {
        switch (fn) {
            case 'random':
                // TODO: we need more settings controlling the random string generation.
                return nanoid(8);
            case 'uuid-v4':
                return uuidV4();
            default:
                return noValue;
        }
    }
    /**
     * Generates a number value based on the function name.
     * @param fn The name of the number generation function.
     * @returns The generated number value (as a string), or `noValue` if the function is not supported.
     */
    generateNumber(fn) {
        switch (fn) {
            case 'incremental':
                return `${this.increment++}`;
            default:
                return noValue;
        }
    }
    /**
     * Generates a date value based on the function name.
     * @param fn The name of the date generation function.
     * @returns The generated date value (as a string in YYYY-MM-DD format),
     * or `noValue` if the function is not supported.
     */
    generateDate(fn) {
        if (fn === 'now') {
            // Returns YYYY-MM-DD
            // @TODO: Replace with Temporal when widely available.
            const d = new Date();
            const year = d.getFullYear();
            const month = `${d.getMonth() + 1}`.padStart(2, '0');
            const day = `${d.getDate()}`.padStart(2, '0');
            return `${year}-${month}-${day}`;
        }
        return noValue;
    }
    /**
     * Generates a time value based on the function name.
     * @param fn The name of the time generation function.
     * @returns The generated time value (as a string in HH:mm:ss format), or `noValue` if the function is not supported.
     */
    generateTime(fn) {
        if (fn === 'now') {
            // Returns HH:mm:ss
            // @TODO: Replace with Temporal when widely available.
            const d = new Date();
            const hour = `${d.getHours()}`.padStart(2, '0');
            const minute = `${d.getMinutes()}`.padStart(2, '0');
            const second = `${d.getSeconds()}`.padStart(2, '0');
            return `${hour}:${minute}:${second}`;
        }
        return noValue;
    }
    /**
     * Generates a datetime value based on the function name.
     * @param fn The name of the datetime generation function.
     * @returns The generated datetime value (as a string in YYYY-MM-DDTHH:mm:ss format),
     * or `noValue` if the function is not supported.
     */
    generateDateTime(fn) {
        if (fn === 'now') {
            // Returns YYYY-MM-DDTHH:mm:ss
            // @TODO: Replace with Temporal when widely available.
            const d = new Date();
            const year = d.getFullYear();
            const month = `${d.getMonth() + 1}`.padStart(2, '0');
            const day = `${d.getDate()}`.padStart(2, '0');
            const hour = `${d.getHours()}`.padStart(2, '0');
            const minute = `${d.getMinutes()}`.padStart(2, '0');
            const second = `${d.getSeconds()}`.padStart(2, '0');
            return `${year}-${month}-${day}T${hour}:${minute}:${second}`;
        }
        return noValue;
    }
}
//# sourceMappingURL=DataValueGenerator.js.map