import CalculationStore from 'client/stores/CalculationStore';
import { currentDate } from 'core/tools/date';
import composeRequest from './composeRequest';

CalculationStore.options = {
  selectRegionRegistration: [
    {
      evo_name: 'Рязанская область',
      value: 'rznregion',
    },
  ],
  selectTownRegistration: [
    {
      evo_name: 'Рязань',
      value: 'rzntown',
    },
  ],
  selectGPSBrand: [
    {
      evo_id: 'gps_brand_evo_id',
      value: 'gpsbrand',
    },
  ],
  selectGPSModel: [
    {
      evo_id: 'gps_model_evo_id',
      value: 'gpsmodel',
    },
  ],
  selectBrand: [
    {
      evo_id: 'AUDI',
      value: 'brandid',
    },
  ],
  selectModel: [
    {
      evo_id: 'A5',
      value: 'modelid',
    },
  ],
};

CalculationStore.values = {
  regionRegistration: 'rznregion',
  townRegistration: 'rzntown',
  brand: 'brandid',
  model: 'modelid',
  leaseObjectUsed: false,
  leaseObjectYear: 2021,
  leaseObjectMotorPower: 5.5,
  engineType: undefined,
  leasingPeriod: 12,
  leaseObjectPrice: 2000,
  supplierDiscountRub: 1000,
  insFranchise: 5,
  GPSBrand: 'gpsbrand',
  GPSModel: 'gpsmodel',
  insUnlimitDrivers: true,
  leaseObjectCategory: 100000002,
  maxMass: 1000,
  leaseObjectUseFor: 100000001,
  INNForCalc: 1010,
};

CalculationStore.tables = {
  tableInsurance: {
    rows: [{}, {}, { insCost: 10000 }],
  },
};

const expected = {
  preparams: {
    regionName: 'Рязанская область',
    cityName: 'Рязань',
    brandId: 'AUDI',
    modelId: 'A5',
  },
  ELTParams: {
    currency: 'RUR',
    isNew: false,
    usageStart: currentDate,
    vehicleYear: 2021,
    modification: {
      power: 5.5,
      engineType: '5',
      engineVolume: 0,
      KPPTypeId: '1',
      BodyType: '9',
    },
    duration: 12,
    bankId: '245',
    cost: 1000,
    franchise: '5',
    ssType: '1',
    STOA: '0',
    OfficialDealer: true,
    PUUs: [
      {
        mark: 'gps_brand_evo_id',
        model: 'gps_model_evo_id',
      },
    ],
    driversCount: 1,
    risk: 0,
    payType: 0,
    vehicle: {
      maxAllowedMass: 1000,
      mileage: 0,
      vehicleUsage: 1,
      seatingCapacity: 0,
      category: 'C2',
      classification: '11635',
    },
    drivers: [{ age: 18, experience: 0, sex: '0' }],
    GO: { limitSumId: '1000000', globalLimitSum: 1000000 },
    NS: { LimitSum: 1000000 },
    Insurer: {
      SubjectType: 1,
      SubjectTypeSpecified: true,
    },
    Owner: {
      SubjectType: 1,
      SubjectTypeSpecified: true,
    },
    Lessee: {
      SubjectType: 1,
      SubjectTypeSpecified: true,
      INN: '1010',
    },
    FullDriversInfo: [
      {
        surname: 'Иванов',
        name: 'Иван',
        patronymic: 'Иванович',
        sex: '0',
        expertienceStart: new Date('2000-01-01'),
      },
    ],
  },
};

it('ELT/Kasko/composeRequest', () => {
  expect(composeRequest.call(CalculationStore)).toEqual(expected);
});
