import { ElementsNames } from 'client/Containers/Calculation/types/elements';
import { ValidationCondition } from 'core/validation/validate';
import { omit } from 'lodash';
import { conditions as kaskoConditions } from '../../Kasko/lib/validation';

export const requiredFields: ElementsNames[] = [
  'selectBrand',
  'selectModel',
  'tbxLeaseObjectYear',
  'tbxLeaseObjectMotorPower',
  'tbxLeasingPeriod',
  'tbxLeaseObjectPrice',
  'selectLeaseObjectUseFor',
  'tbxMaxMass',
  'tbxCountSeats',
  'cbxWithTrailer',
  'tbxINNForCalc',
  'radioObjectRegistration',
  'radioInfuranceOPF',
];

const osagoConditions: Partial<Record<ElementsNames, ValidationCondition>> = {
  selectTownRegistration: calculationStore => {
    const objectRegistration = calculationStore.getValue('objectRegistration');
    if (objectRegistration === 100000001) {
      const townRegistration = calculationStore.getValue('townRegistration');
      if (!townRegistration) {
        return {
          isValid: false,
          message: 'Не указан Город регистрации',
        };
      }
    }
    return {
      isValid: true,
    };
  },
};

const conditions = Object.assign(
  osagoConditions,
  omit(kaskoConditions, ['selectEngineType']),
);

export const resetFields: ElementsNames[] = [
  ...requiredFields,
  ...(Object.keys(conditions) as ElementsNames[]),
  'selectLegalClientTown',
  'selectLegalClientRegion',
  'radioObjectRegistration',
  'selectTownRegistration',
];

export default {
  requiredFields,
  conditions,
};
