import { LoanStatus, LoanTypes } from "@/enums";
import { Amount, Currency, Money } from "./Money";

export interface LoanApplication {
  loanApplicationId: number;
  amount: number;
  paymentDay: number;
  installments: number;
  type: LoanTypes;
}

export class FetchLoanApplicationRequest {
  constructor(public Type: LoanTypes) {}
}

export class CreateApplicationRequest {
  amount: Amount;
  paymentDay: number;
  installments: number;
  type: LoanTypes;

  constructor(
    amount: Amount,
    paymentDay: number,
    installments: number,
    type: LoanTypes
  ) {
    this.amount = this.amount;
    this.paymentDay = paymentDay;
    this.installments = installments;
    this.type = type;
  }
}

export class PrescoreRequest {
  type: LoanTypes;

  constructor(type: LoanTypes) {
    this.type = type;
  }
}

export interface PrescoreResponse {
  continue: boolean;
  loanId: number;
  scoreFields: ScoreField[];
}

export interface ScoreField {
  scoreFieldModelId: string;
  label: string;
  type: number;
  values: string[];
  regex: string;
  error: string;
  isRequired: boolean;
  orderIndex: number;
  pageNumber: number;
  maxLength: number;
  depends: any;
  data: {
    key: string;
    value: string;
  }[];

  //type values
  // 1 - String
  // 2 - Decimal
  // 3 - Select
  // 4 - Contacts
}

export class DeleteApplicationRequest {
  constructor(public loanApplicationId: number) {}
}

export class ScoreRequest {
  constructor(public loanId: number, public scoreFields: ScoreInquiry) {}
}

export interface ScoreResponse {
  loanId: number;
  amount: number;
  rate: number;
  offers: LoanOffer[];
}

export interface LoanOffer {
  amount: number;
  installments: number;
  effectiveRate: number;
  totalRepayment: number;
}

export class UpdateApplicationRequest {
  constructor(public loanId: number, public installments: number) {}
}

export interface LoanResponse {
  loan: Loan;
}

export class LoanProductRequest {
  Type: LoanTypes;
  CurrencyCode: Currency;
  constructor(Type: LoanTypes, CurrencyCode: Currency) {
    this.Type = Type;
    this.CurrencyCode = CurrencyCode;
  }
}

export interface LoanProductResponse {
  loanProduct: LoanProduct;
}

export interface LoanProduct {
  minAmount: Money;
  maxAmount: Money;
  minPaymentDay: number;
  maxPaymentDay: number;
  minInstallments: number;
  maxInstallments: number;
  minInterestRate: number;
  maxInterestRate: number;
  type: number;
}

export class FetchLoanDetailsRequest {
  constructor(public LoanId: number) {}
}

export class RepayLoanRequest {
  loanId: number;
  cardId: string;
  amount: Amount;
  otpToken: string;
  localAuthenticationId: string;

  constructor(
    loanId: number,
    cardId: string,
    amount: Amount,
    otpToken: string,
    localAuthenticationId?: string
  ) {
    this.loanId = loanId;
    this.cardId = cardId;
    this.amount = amount;
    this.otpToken = otpToken;
    this.localAuthenticationId = localAuthenticationId;
  }
}

export class LoanScheduleRequest {
  LoanId: number;

  constructor(LoanId: number) {
    this.LoanId = LoanId;
  }
}

export interface LoanScheduleResponse {
  scheduleItems: ScheduleItem[];
  specialOfferScheduleItems: ScheduleItem[];
}

export interface ScheduleItem {
  amount: Money;
  paymentDay: number;
  paymentMonth: number;
  paymentYear: number;
  principal: number;
  interest: number;
}

export interface ScoreInquiry {
  "8103_LNI_Contact_1_Phone"?: string;
  "8104_LNI_Contact_1_FullName"?: string;
  "8105_LNI_Contact_1_Conn_Type"?: string;
  "8107_LNI_Contact_2_FullName"?: string;
  "8108_LNI_Contact_2_Conn_Type"?: string;
  "8106_LNI_Contact_2_Phone"?: string;
  "8102_LNI_Declared_Other_Income"?: number;
  "8101_LNI_Declared_Salary"?: number;
  "3106_KYC_Workplace"?: string;
  "229_Has_Overdue_Loan"?: boolean;
}

export class Inquiry {
  "8103_LNI_Contact_1_Phone": string;
  "8104_LNI_Contact_1_FullName": string;
  "8105_LNI_Contact_1_Conn_Type": string;
  "8107_LNI_Contact_2_FullName": string;
  "8108_LNI_Contact_2_Conn_Type": string;
  "8106_LNI_Contact_2_Phone": string;
  "8102_LNI_Declared_Other_Income": number;
  "8101_LNI_Declared_Salary": number;
  "3106_KYC_Workplace"?: string;
  "229_Has_Overdue_Loan"?: boolean;

  constructor(
    name1: string,
    conType1: string,
    phone1: string,
    name2: string,
    conType2: string,
    phone2: string,
    salary: number,
    otherIncome: number,
    workplace?: string,
    hasOverdue?: boolean
  ) {
    this["8103_LNI_Contact_1_Phone"] = phone1;
    this["8104_LNI_Contact_1_FullName"] = name1;
    this["8105_LNI_Contact_1_Conn_Type"] = conType1;
    this["8107_LNI_Contact_2_FullName"] = name2;
    this["8108_LNI_Contact_2_Conn_Type"] = conType2;
    this["8106_LNI_Contact_2_Phone"] = phone2;
    this["8102_LNI_Declared_Other_Income"] = otherIncome;
    this["8101_LNI_Declared_Salary"] = salary;
    this["3106_KYC_Workplace"] = workplace;
    this["229_Has_Overdue_Loan"] = hasOverdue;
  }
}

export class FetchLoanConditionsRequest {
  constructor(public LoanId: number) {}
}

export interface Conditions {
  amount: Money;
  term: number;
  rate: number;
  effectiveRate: number;
  monthlyAmount: Money;
  paymentDay: number;
  prepaymentFee: number;
  dailyOverdueFee: Money;
  disbursementFee: Money;
  nextPaymentDay: number;
  nextPaymentMonth: number;
  nextPaymentAmount: Money;
  leftInstallments: number;
  repaymentDate: number;
  totalRepayment: Money;
  contractUrl: string;
  conditions: {
    key: string;
    value: string;
  }[];
}
export class CreateLoanRequest {
  constructor(
    public loanId: number,
    public cardId: string,
    public otpToken: string,
    public sourceCardId?: string,
    public localAuthenticationId?: string
  ) {}
}

export class LoanCloseRequest {
  constructor(public loanId: number) {}
}

export interface Loan {
  loanId: number;
  amount: Money;
  principal: Money;
  interest: Money;
  currentDue: Money;
  term: number;
  rate: number;
  effectiveRate: number;
  monthlyAmount: Money;
  paymentDay: number;
  nextPaymentDay: number;
  nextPaymentMonth: number;
  prepaymentFee: number;
  leftInterest: number;
  leftInstallments: number;
  disbursementDate: string;
  repaymentDate: string;
  nextPaymentAmount: Money;
  overdueAmount: Money;
  overdueDays: number;
  penaltyBalance: number;
  canBeRescheduled: boolean;
  requiresRepaymentForReschedule: boolean;
  canBePostponed: boolean;
  requiresRepaymentForPostpone: boolean;
  dailyOverdueFee: Money;
  totalRepayment: Money;
  status: LoanStatus;
  notes: string;
  type: LoanTypes;
  merchantName: string;
  orderId: string;
  specialOfferStatus: number;
  specialOfferNextPaymentAmount: number;
  specialOfferCurrentDue: number;
  specialOfferInstallments: number;
  specialOfferPaymentAmount: number;
  specialOfferEffectiveRate: number;
  gracePeriod: number;
  gracePeriodDisbursementFeeRate: number;
  gracePeriodDisbursementFee: number;
  isInGracePeriod: true;
  showRepayInfo: boolean;
  canBeChangedConditions: boolean;
  isTranche: boolean;
  isSalaryBacked: boolean;
  minRepaymentAmountForScheduleEditOffer: number;
  isSchedulePaymentDate: boolean;
  totalBalance: Money;
  products: {
    title: string;
    model: string;
    quantity: number;
    amount: number;
    imageUrl: string;
  }[];
  refinanceApplication: RefinanceApplication;
  rescheduleApplication: RescheduleApplication;
  postponeApplication: PostponeApplication;
}

export interface PostponeApplication {
  loanId: number;
  amount: Money;
  addAmount: Money;
  status: LoanStatus;
  notes: string;
  type: LoanTypes;
}

export interface RescheduleApplication {
  loanId: number;
  amount: Money;
  addAmount: Money;
  status: LoanStatus;
  notes: string;
  type: LoanTypes;
}

export interface RefinanceApplication {
  loanId: number;
  amount: Money;
  addAmount: Money;
  status: LoanStatus;
  notes: string;
  type: LoanTypes;
}

export class LoanCheckCardRequest {
  constructor(public loanId: number, public cardId: string) {}
}
