import { FFMPEG_TIME_PATTERN } from './bond.js';
import _ from 'lodash';
import { z } from 'zod';
import { replaceFileExtension } from '../../code/tool/shared/screen.js';
import { getPathType } from '../tool/shared/file.js';
export const transform_input_output_file = {
    form: 'make',
    make: (v, ctx) => {
        if (!v.output.file.path) {
            if (!v.output.format) {
                ctx.addIssue({
                    code: z.ZodIssueCode.custom,
                    message: `Must specify a an output file path or format.`,
                    path: ['output', 'file'],
                });
            }
            else {
                v.output.file.path = replaceFileExtension(v.input.file.path, `.${v.output.format}`);
            }
        }
        return v;
    },
};
export const validate_input_file_path_or_content = {
    form: 'make',
    make: (v, ctx) => {
        if (!v.input.file.path) {
            if (!v.input.file.content) {
                ctx.addIssue({
                    code: z.ZodIssueCode.custom,
                    message: `Must specify either input file path or content.`,
                    path: ['input', 'file'],
                });
            }
        }
        return v;
    },
};
export const is_sha256 = {
    form: 'test',
    test: (bond, name) => Boolean(bond.match(/^[abcdef0123456789]{64}$/i)) ||
        `${name} is not a valid SHA256 hash.`,
};
export const is_remote_path = {
    form: 'test',
    test: (bond, name) => getPathType(bond) !== 'file-uri' ||
        `${name} not a valid remote URI.`,
};
export const is_local_path = {
    form: 'test',
    test: (bond, name) => getPathType(bond) === 'file-uri' ||
        `${name} not a valid local URI.`,
};
export const is_hex_color_8 = {
    form: 'test',
    test: (bond, name) => Boolean(bond.match(/^[abcdef0123456789]{8}$/i) ||
        bond.match(/^[abcdef0123456789]{6}$/i) ||
        `${name} is not a valid hex code.`),
};
export const is_hex_color_6 = {
    form: 'test',
    test: (bond, name) => Boolean(bond.match(/^[abcdef0123456789]{6}$/i)) ||
        `${name} is not a valid hex code.`,
};
export const test_time_string = {
    form: 'test',
    test: (bond, name) => !!bond.match(FFMPEG_TIME_PATTERN) ||
        `${name} has an invalid format.`,
};
export const test_time_integer = {
    form: 'test',
    test: (bond, name) => (Number.isInteger(bond) && bond > 0 && bond < 60) ||
        `${name} has an invalid format.`,
};
export const test_image_magic_color_matrix = {
    form: 'test',
    test: (bond, name) => {
        if (bond.row < 3 || bond.row > 6) {
            return `Color matrix can only have between 3 and 6 rows.`;
        }
        if (bond.column < 3 || bond.column > 6) {
            return `Color matrix can only have between 3 and 6 columns.`;
        }
        const total = bond.row * bond.column;
        if (bond.value.length !== total) {
            return `Color matrix has incorrect number of blocks, needs ${total}.`;
        }
        return true;
    },
};
export const hex_color = {
    form: 'test',
    test: (bond, name) => {
        if (!bond.match(/#[abcdef0-9]{6}/i)) {
            const prop = _.capitalize(_.snakeCase(name)).replace(/_/g, ' ');
            return `${prop} must be a hex string like '#ff0000'.`;
        }
        return true;
    },
};
//# sourceMappingURL=code.js.map