/**
 * Classifier utilities — thin convenience layer over window.zddc.
 */
(function() {
    'use strict';

    /**
     * Compute new filename from file fields.
     * ZDDC format: trackingNumber_revision (status) - title.ext
     * Falls back to original filename if any required ZDDC field is missing.
     */
    function computeNewFilename(file) {
        if (file.manualFilename) {
            return file.manualFilename;
        }

        const formatted = zddc.formatFilename({
            trackingNumber: file.trackingNumber || '',
            revision:       file.revision || '',
            status:         file.status   || '',
            title:          file.title    || '',
            extension:      file.extension || '',
        });

        return formatted || zddc.joinExtension(file.originalFilename, file.extension);
    }

    /**
     * Get column value from file object.
     */
    function getColumnValue(file, columnName) {
        switch (columnName) {
            case 'original':       return file.originalFilename || '';
            case 'extension':      return file.extension || '';
            case 'new':
            case 'newFilename':    return file.manualFilename || computeNewFilename(file);
            case 'trackingNumber': return file.trackingNumber || '';
            case 'revision':       return file.revision || '';
            case 'status':         return file.status || '';
            case 'title':          return file.title || '';
            case 'sha256':         return file.sha256 || '';
            default:               return '';
        }
    }

    /**
     * Get MIME type from file extension (no leading dot).
     */
    const MIME_TYPES = {
        pdf:  'application/pdf',
        jpg:  'image/jpeg',
        jpeg: 'image/jpeg',
        png:  'image/png',
        gif:  'image/gif',
        svg:  'image/svg+xml',
        webp: 'image/webp',
        bmp:  'image/bmp',
        ico:  'image/x-icon',
        txt:  'text/plain',
        md:   'text/markdown',
        json: 'application/json',
        xml:  'application/xml',
        csv:  'text/csv',
        html: 'text/html',
        css:  'text/css',
        js:   'text/javascript',
    };

    function getMimeType(extension) {
        return MIME_TYPES[(extension || '').toLowerCase()] || 'application/octet-stream';
    }

    window.app.modules.utils = {
        computeNewFilename,
        getColumnValue,
        getMimeType,
    };
})();
