export type RentalCategory = 'APARTMENT' | 'HOUSE' | 'CAR' | 'MOTORCYCLE' | 'BICYCLE' | 'EBIKE';

export type RentalPeriodType = 'DAILY' | 'MONTHLY';

export type RentalListingStatus = 'DRAFT' | 'PENDING_REVIEW' | 'ACTIVE' | 'PAUSED' | 'DELETED';

export type BookingStatus = 'PENDING' | 'CONFIRMED' | 'ACTIVE' | 'COMPLETED' | 'CANCELLED_BY_TENANT' | 'CANCELLED_BY_LANDLORD' | 'REJECTED' | 'EXPIRED';

export type PayoutStatus = 'PENDING' | 'PROCESSING' | 'COMPLETED' | 'FAILED';

export type CancellationPolicy = 'FLEXIBLE' | 'MODERATE' | 'STRICT';

export interface RentalImage {
  id: string;
  url: string;
  order: number;
}

export interface RentalListing {
  id: string;
  title: string;
  description: string;
  category: RentalCategory;
  location: string;
  dailyPrice?: number | null;
  monthlyPrice?: number | null;
  depositAmount?: number | null;
  details?: Record<string, unknown>;
  amenities: string[];
  rules: string[];
  cancellationPolicy: CancellationPolicy;
  minDays?: number | null;
  maxDays?: number | null;
  minMonths?: number | null;
  maxMonths?: number | null;
  status: RentalListingStatus;
  viewCount: number;
  isFeatured: boolean;
  isVerified: boolean;
  rejectionReason?: string | null;
  landlordId: string;
  landlord: {
    id: string;
    fullName: string;
    nickname?: string;
    avatar?: string;
    rating?: number;
    location?: string;
    landlordVerified?: boolean;
    createdAt: string;
  };
  images: RentalImage[];
  isFavorited?: boolean;
  avgRating?: number;
  _count?: {
    favorites: number;
    bookings: number;
    reviews: number;
  };
  reviews?: RentalReview[];
  createdAt: string;
  updatedAt: string;
}

export interface Booking {
  id: string;
  rentalListingId: string;
  tenantId: string;
  landlordId: string;
  periodType: RentalPeriodType;
  startDate: string;
  endDate: string;
  pricePerPeriod: number;
  totalPeriods: number;
  subtotal: number;
  commissionRate: number;
  commissionAmount: number;
  depositAmount: number;
  totalAmount: number;
  status: BookingStatus;
  message?: string;
  rejectionReason?: string;
  cancellationReason?: string;
  stripePaymentIntentId?: string;
  expiresAt?: string;
  rentalListing: {
    id: string;
    title: string;
    category: RentalCategory;
    location: string;
    cancellationPolicy: CancellationPolicy;
    images: RentalImage[];
  };
  tenant: { id: string; fullName: string; nickname?: string; avatar?: string };
  landlord: { id: string; fullName: string; nickname?: string; avatar?: string };
  payout?: Payout | null;
  review?: RentalReview | null;
  createdAt: string;
  updatedAt: string;
}

export interface Payout {
  id: string;
  bookingId: string;
  landlordId: string;
  grossAmount: number;
  commissionAmount: number;
  netAmount: number;
  status: PayoutStatus;
  stripeTransferId?: string;
  booking?: {
    id: string;
    rentalListing: { id: string; title: string };
    tenant?: { id: string; fullName: string };
    startDate: string;
    endDate: string;
  };
  createdAt: string;
  updatedAt: string;
}

export interface RentalReview {
  id: string;
  bookingId: string;
  rentalListingId: string;
  tenantId: string;
  landlordId: string;
  rating: number;
  comment?: string;
  landlordResponse?: string;
  tenant?: { id: string; fullName: string; avatar?: string };
  rentalListing?: { id: string; title: string };
  createdAt: string;
  updatedAt: string;
}

export interface AvailabilityBlock {
  id: string;
  rentalListingId: string;
  startDate: string;
  endDate: string;
  isBlocked: boolean;
  reason?: string;
}

export interface RentalStats {
  totalRentals: number;
  activeRentals: number;
  pendingRentals: number;
  totalBookings: number;
  activeBookings: number;
  completedBookings: number;
  totalPayouts: number;
  pendingPayouts: number;
  totalRentalRevenue: number;
  totalPaidOut: number;
}
