/*!
 * Built by ShiftSoftware
 * Copyright (c)
 */
import { number, object, string } from "yup";
import validateVin from "../../../global/lib/validate-vin";
export const label = (name) => `${name}-label`;
export const format = (name) => `${name}-format`;
export const require = (name) => `${name}-require`;
export const size = (name) => `${name}-size`;
export const max = (name) => `${name}-max`;
export const placeholder = (name) => `${name}-placeholder`;
export const meta = (name) => ({ label: label(name), placeholder: placeholder(name) });
export const condition = (name) => `$${name}Required`;
export const y = { label, format, require, condition, placeholder, meta, size, max };
export const getFormValidations = (extraFields = {}) => {
    return object(Object.assign({ name: string()
            .meta(meta('name'))
            .when(condition('name'), {
            is: true,
            otherwise: schema => schema.optional(),
            then: schema => schema.required(require('name')).min(3, format('name')),
        }), lastName: string()
            .meta(meta('lastName'))
            .when(condition('lastName'), {
            is: true,
            otherwise: schema => schema.optional(),
            then: schema => schema.required(require('lastName')).min(3, format('lastName')),
        }), message: string()
            .meta(meta('message'))
            .when(condition('message'), {
            is: true,
            otherwise: schema => schema.optional(),
            then: schema => schema.required(require('message')).min(10, format('message')),
        }), email: string()
            .meta(meta('email'))
            .when(condition('email'), {
            is: true,
            otherwise: schema => schema.optional(),
            then: schema => schema.required(require('email')),
        })
            .email(format('email')), vin: string()
            .meta(meta('vin'))
            .when(condition('vin'), {
            is: true,
            otherwise: schema => schema.optional(),
            then: schema => schema.required(require('vin')).test(format('vin'), format('vin'), a => validateVin(a === null || a === void 0 ? void 0 : a.toUpperCase())),
        }), vehicle: string()
            .meta(meta('vehicle'))
            .when(y.condition('vehicle'), {
            is: true,
            otherwise: schema => schema.optional(),
            then: schema => schema.required(y.require('vehicle')),
        }), vacancyId: string()
            .meta(meta('vacancyId'))
            .when(y.condition('vacancyId'), {
            is: true,
            otherwise: schema => schema.optional(),
            then: schema => schema.required(y.require('vacancyId')),
        }), companyBranchId: string()
            .meta(meta('companyBranchId'))
            .when(y.condition('companyBranchId'), {
            is: true,
            otherwise: schema => schema.optional(),
            then: schema => schema.required(y.require('companyBranchId')),
        }), cityId: string()
            .meta(meta('cityId'))
            .when(y.condition('cityId'), {
            is: true,
            otherwise: schema => schema.optional(),
            then: schema => schema.required(y.require('cityId')),
        }), date: string()
            .meta(meta('date'))
            .when(condition('date'), {
            is: true,
            otherwise: schema => schema.optional(),
            then: schema => schema.required(require('date')),
        }), year: string()
            .meta(meta('year'))
            .when(condition('year'), {
            is: true,
            otherwise: schema => schema.optional(),
            then: schema => schema.required(require('year')),
        }), time: string()
            .meta(meta('time'))
            .when(condition('time'), {
            is: true,
            otherwise: schema => schema.optional(),
            then: schema => schema.required(require('time')),
        }), currentVehicleBrand: string()
            .meta(meta('currentVehicleBrand'))
            .when('ownVehicle', {
            is: (val) => val === 'yes',
            then: schema => schema.required(require('currentVehicleBrand')),
            otherwise: schema => schema.optional(),
        }), currentVehicleModel: string()
            .meta(meta('currentVehicleModel'))
            .when(['ownVehicle', 'currentVehicleBrand'], {
            is: (ownVehicle, brand) => ownVehicle === 'yes' && brand !== 'Other',
            then: schema => schema.required(require('currentVehicleModel')),
            otherwise: schema => schema.optional(),
        }), ownVehicle: string()
            .meta(meta('ownVehicle'))
            .when(condition('ownVehicle'), {
            is: true,
            otherwise: schema => schema.optional(),
            then: schema => schema.required(require('ownVehicle')),
        }), conditionalCurrentVehicleBrand: string()
            .meta(meta('currentVehicleBrand'))
            .when('ownVehicle', {
            is: (val) => val === 'yes',
            then: schema => schema.required(require('currentVehicleBrand')),
            otherwise: schema => schema.optional(),
        }), conditionalCurrentVehicleModel: string()
            .meta(meta('currentVehicleModel'))
            .when(['ownVehicle', 'conditionalCurrentVehicleBrand'], {
            is: (ownVehicle, brand) => ownVehicle === 'yes' && brand !== 'Other',
            then: schema => schema.required(require('currentVehicleModel')),
            otherwise: schema => schema.optional(),
        }), gender: number()
            .meta(meta('gender'))
            .when(condition('gender'), {
            is: true,
            otherwise: schema => schema.optional(),
            then: schema => schema.required(require('gender')),
        }) }, extraFields));
};
