export interface Address {
  id: string;
  userId: string;
  address1: string;
  address2?: string;
  city: string;
  state: string;
  zipCode: string;
  country: string;
  latitude?: number;
  longitude?: number;
  isPrimary: boolean;
  createdAt: string;
  updatedAt: string;
}

export interface User {
  id: string;
  username: string;
  email: string;
  firstName: string;
  lastName: string;
  phone?: string;
  address1?: string;
  address2?: string;
  city?: string;
  state?: string;
  zipCode?: string;
  country?: string;
  imageFilename?: string;
  isVerified: boolean;
  role?: "user" | "admin";
  stripeConnectedAccountId?: string;
  addresses?: Address[];
  itemRequestNotificationRadius?: number;
  // Ban-related fields (only visible to admins)
  isBanned?: boolean;
  bannedAt?: string;
  bannedBy?: string;
  banReason?: string;
}

export interface Message {
  id: string;
  senderId: string;
  receiverId: string;
  content: string;
  isRead: boolean;
  imageFilename?: string;
  sender?: User;
  receiver?: User;
  createdAt: string;
  updatedAt: string;
}

export interface Conversation {
  partnerId: string;
  partner: User;
  lastMessage: {
    id: string;
    content: string;
    senderId: string;
    createdAt: string;
    isRead: boolean;
  };
  unreadCount: number;
  lastMessageAt: string;
}

export interface Item {
  id: string;
  name: string;
  description: string;
  pricePerHour?: number;
  pricePerDay?: number;
  pricePerWeek?: number;
  pricePerMonth?: number;
  replacementCost: number;
  address1?: string;
  address2?: string;
  city?: string;
  state?: string;
  zipCode?: string;
  country?: string;
  latitude?: number;
  longitude?: number;
  imageFilenames: string[];
  condition: "excellent" | "good" | "fair" | "poor";
  isAvailable: boolean;
  rules?: string;
  availableAfter?: string;
  availableBefore?: string;
  specifyTimesPerDay?: boolean;
  weeklyTimes?: {
    sunday: { availableAfter: string; availableBefore: string };
    monday: { availableAfter: string; availableBefore: string };
    tuesday: { availableAfter: string; availableBefore: string };
    wednesday: { availableAfter: string; availableBefore: string };
    thursday: { availableAfter: string; availableBefore: string };
    friday: { availableAfter: string; availableBefore: string };
    saturday: { availableAfter: string; availableBefore: string };
  };
  ownerId: string;
  owner?: User;
  isDeleted?: boolean;
  deletedBy?: string;
  deletedAt?: string;
  deletionReason?: string;
  deleter?: User;
  createdAt: string;
  updatedAt: string;
}

export type RentalStatus =
  | "pending"
  | "confirmed"
  | "declined"
  | "active"
  | "completed"
  | "cancelled"
  | "returned_late"
  | "returned_late_and_damaged"
  | "damaged"
  | "lost";

export interface Rental {
  id: string;
  itemId: string;
  renterId: string;
  ownerId: string;
  startDateTime: string;
  endDateTime: string;
  totalAmount: number;
  // Fee tracking fields
  platformFee?: number;
  payoutAmount?: number;
  status: RentalStatus;
  // Computed status (includes "active" when confirmed + start time passed)
  displayStatus?: RentalStatus;
  paymentStatus: "pending" | "paid" | "refunded" | "requires_action";
  // Refund tracking fields
  refundAmount?: number;
  refundProcessedAt?: string;
  refundReason?: string;
  stripeRefundId?: string;
  cancelledBy?: "renter" | "owner";
  cancelledAt?: string;
  stripePaymentIntentId?: string;
  stripePaymentMethodId?: string;
  // Payout status tracking
  payoutStatus?: "pending" | "completed" | "failed" | null;
  payoutProcessedAt?: string;
  stripeTransferId?: string;
  // Bank deposit tracking (Stripe payout to owner's bank)
  bankDepositStatus?: "pending" | "in_transit" | "paid" | "failed" | "canceled" | null;
  bankDepositAt?: string;
  stripePayoutId?: string;
  bankDepositFailureCode?: string;
  // Payment failure tracking
  paymentFailedNotifiedAt?: string;
  paymentFailedReason?: string;
  paymentMethodUpdatedAt?: string;
  intendedUse?: string;
  rating?: number;
  review?: string;
  declineReason?: string;
  // New review fields
  itemRating?: number;
  itemReview?: string;
  itemReviewSubmittedAt?: string;
  itemReviewVisible?: boolean;
  renterRating?: number;
  renterReview?: string;
  renterReviewSubmittedAt?: string;
  renterReviewVisible?: boolean;
  // Private messages
  itemPrivateMessage?: string;
  renterPrivateMessage?: string;
  // New condition check and dispute fields
  actualReturnDateTime?: string;
  lateFees?: number;
  damageFees?: number;
  replacementFees?: number;
  itemLostReportedAt?: string;
  damageAssessment?: any;
  item?: Item;
  renter?: User;
  owner?: User;
  createdAt: string;
  updatedAt: string;
}

export interface ConditionCheck {
  id: string;
  rentalId: string;
  checkType:
    | "pre_rental_owner"
    | "rental_start_renter"
    | "rental_end_renter"
    | "post_rental_owner";
  imageFilenames: string[];
  notes?: string;
  submittedBy: string;
  submittedAt: string;
  submittedByUser?: User;
  createdAt: string;
  updatedAt: string;
}

export interface LateReturnCalculation {
  lateHours: number;
  lateFee: number;
  isLate: boolean;
  gracePeriodUsed?: boolean;
  billableHours?: number;
  pricingType?: "hourly" | "daily";
}

export interface DamageAssessment {
  description: string;
  canBeFixed: boolean;
  repairCost?: number;
  needsReplacement: boolean;
  replacementCost?: number;
  proofOfOwnership?: string[];
  imageFilenames?: string[];
  assessedAt: string;
  assessedBy: string;
  feeCalculation: {
    type: "repair" | "replacement" | "assessment";
    amount: number;
    originalCost?: number;
    repairCost?: number;
    percentage?: number;
    baseAmount?: number;
  };
}

export interface ConditionCheckTimeline {
  rental: {
    id: string;
    startDateTime: string;
    endDateTime: string;
    status: string;
  };
  timeline: {
    [key: string]: {
      status:
        | "completed"
        | "available"
        | "pending"
        | "expired"
        | "not_available";
      submittedAt?: string;
      submittedBy?: User;
      photoCount?: number;
      hasNotes?: boolean;
      timeWindow?: {
        start: string;
        end: string;
      };
      availableFrom?: string;
      availableUntil?: string;
    };
  };
}

export interface ForumPost {
  id: string;
  title: string;
  content: string;
  authorId: string;
  category: "item_request" | "technical_support" | "community_resources" | "general_discussion";
  status: "open" | "answered" | "closed";
  viewCount: number;
  commentCount: number;
  isPinned: boolean;
  acceptedAnswerId?: string;
  imageFilenames?: string[];
  zipCode?: string;
  latitude?: number;
  longitude?: number;
  isDeleted?: boolean;
  deletedBy?: string;
  deletedAt?: string;
  closedBy?: string;
  closedAt?: string;
  closer?: User;
  hasDeletedComments?: boolean;
  author?: User;
  tags?: PostTag[];
  comments?: ForumComment[];
  createdAt: string;
  updatedAt: string;
}

export interface ForumComment {
  id: string;
  postId: string;
  authorId: string;
  content: string;
  parentCommentId?: string;
  isDeleted: boolean;
  imageFilenames?: string[];
  deletedBy?: string;
  deletedAt?: string;
  author?: User;
  replies?: ForumComment[];
  createdAt: string;
  updatedAt: string;
}

export interface PostTag {
  id: string;
  postId: string;
  tagName: string;
}

export interface RefundPreview {
  canCancel: boolean;
  cancelledBy: "renter" | "owner";
  refundAmount: number;
  refundPercentage: number;
  reason: string;
  totalAmount: number;
}

export interface Feedback {
  id: string;
  userId: string;
  feedbackText: string;
  userAgent?: string;
  url?: string;
  createdAt: string;
  updatedAt: string;
}
