var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { Store, StoreConfig } from '@datorama/akita';
import { pipe } from 'fp-ts/lib/function';
import * as O from 'fp-ts/Option';
import { v4 as uuidv4 } from 'uuid';
export function createInitialState() {
  return {
    vehicle: {
      make: O.none,
      makeId: O.none,
      model: O.none,
      modelId: O.none,
      year: O.none,
      bodyType: O.none,
      bodyTypeId: O.none,
      selectedVariant: O.none,
      isUsedCarRequested: O.some(false),
      approximatePrice: O.none
    },
    user: {
      annualSalary: O.none,
      annualKms: O.none,
      paymentPeriod: O.none,
      state: O.none,
      term: O.none,
      employmentType: O.none
    },
    quote: {
      afterTaxEffectPerPayCycle: O.none,
      taxSaving: O.none,
      residualValue: O.none,
      financedAmount: O.none,
      fuel: O.none,
      serviceAndMaintenance: O.none,
      registrationAndCtp: O.none,
      comprehensiveInsurance: O.none,
      managementFee: O.none,
      quoteState: 'Not calculated'
    },
    userDetails: {
      employerName: O.none,
      userFirstName: O.none,
      userLastName: O.none,
      contactNumber: O.none,
      emailAddress: O.none
    },
    refLists: {
      makeList: O.none,
      modelList: O.none,
      yearList: O.none,
      bodyTypeList: O.none,
      modelVariantsList: O.none
    },
    distinctUserId: uuidv4()
  };
}
let SessionStore = class SessionStore extends Store {
  constructor() {
    super(createInitialState());
  }
  updateQuote(quote) {
    this.update({
      quote: quote
    });
  }
  setVehicleState(key, value) {
    this.update((state) => (Object.assign(Object.assign({}, state), { vehicle: Object.assign(Object.assign({}, state.vehicle), { [key]: value === null ? O.none : O.some(value) }) })));
  }
  updateList(name, value) {
    this.update((state) => (Object.assign(Object.assign({}, state), { refLists: Object.assign(Object.assign({}, state.refLists), { [name]: O.some(value) }) })));
  }
  setDistinctUserId(userId) {
    pipe(userId, O.fold(() => ({}), (distinctUserId) => this.update((state) => (Object.assign(Object.assign({}, state), { distinctUserId })))));
  }
};
SessionStore = __decorate([
  StoreConfig({ name: 'cars-calc-session', resettable: true })
], SessionStore);
export { SessionStore };
export default new SessionStore();
