// Credit Report Latest API Response Types

export interface CreditReportBorrower {
  BirthDate: string;
  BorrowerID: string;
  FirstName: string;
  LastName: string;
  PrintPositionType: string;
  RESIDENCE: CreditReportResidence[];
  SSN: string;
  UnparsedName: string | null;
}

export interface CreditReportResidence {
  BorrowerResidencyType: string;
  City: string;
  PostalCode: string;
  State: string;
  StreetAddress: string;
  BorrowerID?: string | null;
  BorrowerResidencyDurationMonths?: number;
  BorrowerResidencyDurationYears?: string;
  DateReported?: string;
}

export interface CreditReportInquiry {
  BorrowerID: string;
  City: string;
  CreditBusinessType: string;
  CreditFileID: string;
  CreditInquiryID: string;
  CreditRepository: {
    SourceType: string;
  };
  Date: string;
  InquiryHashComplex: string;
  InquiryHashSimple: string;
  Name: string;
  Phone: string;
  PostalCode: string;
  PurposeType: string;
  RawIndustryCode: string;
  RawIndustryText: string;
  State: string;
  StreetAddress: string;
}

export interface CreditReportLiability {
  AccountClosedDate: string | null;
  AccountIdentifier: string;
  AccountOpenedDate: string;
  AccountOwnershipType: string;
  AccountPaidDate: string | null;
  AccountReportedDate: string;
  AccountStatusType: string;
  AccountType: string | null;
  ArrayAccountIdentifier: string;
  BorrowerID: string;
  ConsumerDisputeIndicator: boolean;
  CreditBusinessType: string;
  CreditComment: Array<{
    Code: string;
    SourceType: string;
    Type: string;
    Text: string | null;
    TypeOtherDescription: string | null;
  }>;
  CreditFileID: string;
  CreditLiabilityID: string;
  CreditLimitAmount: number | null;
  CreditLoanType: string;
  CreditLoanTypeCode: string;
  CreditTradeReferenceID: string;
  Creditor: {
    City: string;
    ContactDetail: {
      Type: string;
      Value: string;
    };
    Name: string;
    Phone: string;
    PostalCode: string;
    State: string;
    StreetAddress: string;
  };
  CurrentRating: {
    Code: string;
    Type: string;
  };
  DerogatoryDataIndicator: boolean;
  HighBalanceAmount: number | null;
  HighCreditAmount: number | null;
  HighestAdverseRating: {
    Code: string | null;
    Type: string | null;
  };
  IsChargeoffIndicator: boolean;
  IsClosedIndicator: boolean;
  IsCollectionIndicator: boolean;
  IsMortgageIndicator: boolean;
  LastActivityDate: string;
  LastPaymentDate: string | null;
  LateCount: {
    Days30: number;
    Days60: number;
    Days90: number;
  };
  MonthlyPaymentAmount: number | null;
  MonthsReviewedCount: number;
  PastDueAmount: number | null;
  PaymentPattern: Array<{
    Data: string;
    StartDate: string;
  }>;
  RawAccountStatus: string | null;
  RawAccountType: string | null;
  RawIndustryCode: string | null;
  RawIndustryText: string | null;
  SecuredLoanIndicator: string;
  TUI_Handle: string | null;
  TermsDescription: string | null;
  TermsSourceType: string | null;
  TradelineHashComplex: string;
  TradelineHashSimple: string;
  UnpaidBalanceAmount: number | null;
  TermsMonthsCount: number | null;
  OriginalBalanceAmount: number | null;
  CreditBalance: number | null;
  ChargeOffDate: string | null;
  CollectionDate: string | null;
  MostrecentAdverserating_Code: string | null;
  MostrecentAdverserating_Date: string | null;
}

export interface CreditScore {
  BorrowerID: string;
  CreditFileID: string;
  CreditReportIdentifier: string;
  CreditRepositorySourceType: string;
  CreditScoreID: string;
  RiskBasedPricingMax: number;
  RiskBasedPricingMin: number;
  RiskBasedPricingPercent: number;
  Date: string | null;
  ModelNameType: string;
  ModelNameTypeOtherDescription: string;
  Value: number;
  InquiriesAffectedScore: string | null;
  FACTOR: Array<{
    Code: string;
    Text: string;
    Factor_Type: string;
  }>;
}

export interface CreditSummaryDataSet {
  ID: string;
  Name: string;
  Value: string;
}

export interface CreditSummary {
  BorrowerID: string | null;
  DATA_SET: CreditSummaryDataSet[];
  Name: string | null;
}

export interface CreditAlertMessage {
  Code?: string;
  Text?: string;
  Type?: string;
  SourceType?: string;
}

export interface CreditVariation {
  Name?: string;
  Value?: string;
  Type?: string;
}

export interface CreditFile {
  ALERT_MESSAGE: CreditAlertMessage[];
  BORROWER: CreditReportBorrower;
  BorrowerID: string;
  CreditFileID: string;
  CreditRepositorySourceType: string;
  CreditScoreID: string;
  InfileDate: string;
  ResultStatusType: string;
  VARIATION: CreditVariation | null;
}

export interface CreditResponse {
  BORROWER: CreditReportBorrower;
  CREDIT_BUREAU: string;
  CREDIT_FILE: CreditFile;
  CREDIT_FROZEN_STATUS: {
    EquifaxIndicator: string;
    ExperianIndicator: string;
    TransUnionIndicator: string;
  };
  CREDIT_INQUIRY: CreditReportInquiry[];
  CREDIT_LIABILITY: CreditReportLiability[];
  CREDIT_REPOSITORY_INCLUDED: {
    EquifaxIndicator: string;
    ExperianIndicator: string;
    TransUnionIndicator: string;
  };
  CREDIT_REQUEST_DATA: {
    BorrowerID: string;
    CREDIT_REPOSITORY_INCLUDED: {
      EquifaxIndicator: string;
      ExperianIndicator: string;
      TransUnionIndicator: string;
    };
  };
  CREDIT_SCORE: CreditScore[];
  CREDIT_SUMMARY: CreditSummary;
  CREDIT_SUMMARY_TUI: CreditSummary;
  CreditRatingCodeType: string;
  CreditReportFirstIssuedDate: string;
  CreditReportIdentifier: string;
  CreditReportMergeTypeIndicator: string;
  CreditResponseID: string;
  MISMOVersionID: string | null;
  Internal_Client_Key: number;
  Client_key: string;
  Report_ID: number;
  Report_Type: string | null;
  Vendor: string;
}

export interface CreditReportContent {
  CREDIT_RESPONSE: CreditResponse;
}

export interface CreditReportClient {
  id: number;
  salesforce_id: string;
  ssn: string | null;
  email: string;
  mobile_phone: string;
  joint_customer_sf_id: string | null;
  client_key: string;
}

export interface CreditReportData {
  id: number;
  internal_client_key: number;
  client_key: string;
  report_id: number;
  vendor: string;
  bureau: string;
  report_date: string;
  modified_date: string;
  content: CreditReportContent;
  client: CreditReportClient;
}

export interface CreditReportLatestResponse {
  data: CreditReportData;
}

// Helper types for easier access to nested data
export interface CreditReportSummary {
  creditScore: number;
  bureau: string;
  reportDate: string;
  borrowerName: string;
  totalAccounts: number;
  openAccounts: number;
  totalInquiries: number;
  totalBalance: number;
}