export type ListingCondition = "new" | "like_new" | "good" | "fair" | "poor";

export interface ApiListingGalleryItem {
  id: number;
  image: string;
}

export interface ApiListingDetail extends Omit<ApiListing, never> {
  gallery: ApiListingGalleryItem[];
}

export interface ApiListing {
  id: number;
  channel_id: string;
  category_id: number;
  title: string;
  description: string;
  price: number;
  quantity?: number;
  storage_type: number;
  image: string;
  listing_condition: number;
  city: string;
  area: string;
  latitude: string;
  longitude: string;
  total_view: number;
  is_featured: number;
  status: number;
  created_at: string;
  updated_at: string;
  user_full_name: string;
  user_channel_name: string;
  user_image: string;
  user_firebase_id?: string;
  category_name: string;
  is_wishlist: number;
  total_wishlist: number;
  distance_km: string;
}
export type ListingStatus = "active" | "sold" | "paused" | "draft" | "expired";
export type OrderStatus =
  | "placed"
  | "confirmed"
  | "shipped"
  | "out_for_delivery"
  | "delivered"
  | "cancelled"
  | "refunded";
export type PaymentMethod = "card" | "upi" | "netbanking" | "cod" | "wallet";
export type DeliveryType = "standard" | "express" | "pickup";

export interface MarketplaceCategory {
  id: string;
  slug: string;
  label: string;
  icon: string;
  subcategories?: MarketplaceCategory[];
}

export interface ListingImage {
  id: string;
  url: string;
  alt: string;
  isPrimary: boolean;
}

export interface ListingLocation {
  city: string;
  state: string;
  pincode?: string;
  coordinates?: { lat: number; lng: number };
}

export interface Listing {
  id: string;
  slug: string;
  title: string;
  description: string;
  price: number;
  originalPrice?: number;
  images: ListingImage[];
  category: string;
  subcategory?: string;
  condition: ListingCondition;
  status: ListingStatus;
  sellerId: string;
  sellerName: string;
  sellerAvatar: string;
  sellerSlug: string;
  location: ListingLocation;
  views: number;
  wishlisted: number;
  tags: string[];
  specifications?: Record<string, string>;
  createdAt: string;
  updatedAt: string;
}

export interface CartItem {
  listingId: string;
  title: string;
  price: number;
  image: string;
  quantity: number;
  sellerId: string;
  sellerName: string;
}

export interface WishlistItem {
  listingId: string;
  title: string;
  price: number;
  image: string;
  addedAt: string;
}

export interface Address {
  id: string;
  label: string;
  fullName: string;
  phone: string;
  line1: string;
  line2?: string;
  city: string;
  state: string;
  pincode: string;
  isDefault: boolean;
}

export interface OrderItem {
  listingId: string;
  title: string;
  image: string;
  price: number;
  quantity: number;
  condition: ListingCondition;
}

export interface Order {
  id: string;
  buyerId: string;
  sellerId: string;
  sellerName: string;
  items: OrderItem[];
  status: OrderStatus;
  totalAmount: number;
  deliveryAddress: Address;
  paymentMethod: PaymentMethod;
  deliveryType: DeliveryType;
  estimatedDelivery: string;
  trackingId?: string;
  placedAt: string;
  updatedAt: string;
}

export interface Message {
  id: string;
  senderId: string;
  receiverId: string;
  text: string;
  images?: string[];
  listingId?: string;
  listingTitle?: string;
  createdAt: string;
  read: boolean;
}

export interface Conversation {
  id: string;
  participantId: string;
  participantName: string;
  participantAvatar: string;
  lastMessage: string;
  lastMessageAt: string;
  unreadCount: number;
  listingId?: string;
  listingTitle?: string;
  listingImage?: string;
}

export interface SellerEarning {
  orderId: string;
  listingTitle: string;
  amount: number;
  fee: number;
  net: number;
  date: string;
  status: "pending" | "processing" | "paid";
}

export interface SearchFilters {
  query: string;
  category?: string;
  subcategory?: string;
  minPrice?: number;
  maxPrice?: number;
  condition?: ListingCondition[];
  location?: string;
  sortBy?: "relevance" | "price_asc" | "price_desc" | "newest" | "popular";
  deliveryType?: DeliveryType;
}
