import { Company } from "../../models";
import { Loan } from "../Loan";
import { Gender } from "../../enums";
import { Money } from "../Money";

export interface Customer {
  firstName: string;
  lastName: string;
  personalNumber: string;
  isPartiallyVerified: boolean;
  isVerified: boolean;
  workPlace: string;
  salary: Money;
  agreementUrl: string;
  loanContractUrl: string;
  loanContractId: string;
  installmentContractUrl: string;
  installmentContractId: string;
  tbcCollection: boolean;
  isRestructurizationAllowed: boolean;
  gender: number;
  status: number;
  loans: Loan[];
  gamificationParticipationType: number;
  cardDeliveryAddress: string;
  cardDeliveryType: number;
  contractDeliveryAddress: string;
  contractDeliveryType: number;
  tempRegistrationArea: string;
  tempRegistrationCity: string;
  tempRegistrationAddress: string;
  allowSavings: boolean;
  loanRepaymentSourceFriendlyName: string;
  companies: Company[];
  publicRegistryMissingFields: number;
}

export class CreateCustomerRequestUZ {
  PersonalNumber: string;
  FirstNameLat: string;
  LastNameLat: string;
  BirthDate: string;
  DocumentExpirationDate: string;
  PassportNumber: string;
  PassportSeries: string;
  Citizenship: string;
  Gender: Gender;
  DocumentFirstImage: Blob;
  DocumentFirstImageCropped: Blob;
  Selfie: Blob;
  DocumentType?: number;
  DocumentSecondImage?: Blob;

  constructor(data: {
    PersonalNumber: string;
    FirstNameLat: string;
    LastNameLat: string;
    BirthDate: number;
    DocumentExpirationDate: number;
    PassportNumber: string;
    PassportSeries: string;
    Citizenship: string;
    Gender: Gender;
    DocumentFirstImage: Blob;
    DocumentFirstImageCropped: Blob;
    Selfie: Blob;
    DocumentSecondImage?: Blob;
    DocumentType?: number;
  }) {
    this.PersonalNumber = data.PersonalNumber;
    this.FirstNameLat = data.FirstNameLat;
    this.LastNameLat = data.LastNameLat;
    this.BirthDate = data.BirthDate.toString();
    this.DocumentExpirationDate = data.DocumentExpirationDate.toString();
    this.PassportNumber = data.PassportNumber;
    this.PassportSeries = data.PassportSeries;
    this.Citizenship = data.Citizenship;
    this.Gender = data.Gender;
    this.DocumentFirstImage = data.DocumentFirstImage;
    this.DocumentFirstImageCropped = data.DocumentFirstImageCropped;
    this.Selfie = data.Selfie;
    this.DocumentType = data.DocumentType;
    this.DocumentSecondImage = data.DocumentSecondImage;
  }

  formData(): FormData {
    const fd = new FormData();

    for (const key in this) {
      if (typeof this[key] !== "undefined") {
        fd.append(key, (this[key] as unknown) as string);
      }
    }

    return fd;
  }
}
