// Marketplace Types for LocalGreenChain
// These types define the marketplace foundation for plant trading

export enum ListingCategory {
  SEEDS = 'seeds',
  SEEDLINGS = 'seedlings',
  MATURE_PLANTS = 'mature_plants',
  CUTTINGS = 'cuttings',
  PRODUCE = 'produce',
  SUPPLIES = 'supplies',
}

export enum ListingStatus {
  DRAFT = 'draft',
  ACTIVE = 'active',
  SOLD = 'sold',
  EXPIRED = 'expired',
  CANCELLED = 'cancelled',
}

export enum OfferStatus {
  PENDING = 'pending',
  ACCEPTED = 'accepted',
  REJECTED = 'rejected',
  WITHDRAWN = 'withdrawn',
  EXPIRED = 'expired',
}

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

export interface Listing {
  id: string;
  sellerId: string;
  sellerName?: string;
  plantId?: string;
  title: string;
  description: string;
  price: number;
  currency: string;
  quantity: number;
  category: ListingCategory;
  status: ListingStatus;
  location?: {
    lat: number;
    lng: number;
    city?: string;
    region?: string;
  };
  tags: string[];
  images: ListingImage[];
  viewCount: number;
  createdAt: Date;
  updatedAt: Date;
  expiresAt?: Date;
}

export interface Offer {
  id: string;
  listingId: string;
  buyerId: string;
  buyerName?: string;
  amount: number;
  message?: string;
  status: OfferStatus;
  createdAt: Date;
  updatedAt: Date;
  expiresAt?: Date;
}

export interface SellerProfile {
  userId: string;
  displayName: string;
  bio?: string;
  location?: {
    city?: string;
    region?: string;
  };
  rating: number;
  reviewCount: number;
  totalSales: number;
  memberSince: Date;
  verified: boolean;
}

export interface WishlistItem {
  id: string;
  userId: string;
  listingId: string;
  addedAt: Date;
}

export interface SearchFilters {
  query?: string;
  category?: ListingCategory;
  minPrice?: number;
  maxPrice?: number;
  location?: {
    lat: number;
    lng: number;
    radiusKm: number;
  };
  sellerId?: string;
  status?: ListingStatus;
  tags?: string[];
  sortBy?: 'price_asc' | 'price_desc' | 'date_desc' | 'date_asc' | 'relevance';
  page?: number;
  limit?: number;
}

export interface SearchResult {
  listings: Listing[];
  total: number;
  page: number;
  limit: number;
  hasMore: boolean;
}

export interface CreateListingInput {
  title: string;
  description: string;
  price: number;
  currency?: string;
  quantity: number;
  category: ListingCategory;
  plantId?: string;
  location?: {
    lat: number;
    lng: number;
    city?: string;
    region?: string;
  };
  tags?: string[];
  expiresAt?: Date;
}

export interface UpdateListingInput {
  title?: string;
  description?: string;
  price?: number;
  quantity?: number;
  status?: ListingStatus;
  tags?: string[];
  expiresAt?: Date;
}

export interface CreateOfferInput {
  listingId: string;
  amount: number;
  message?: string;
}

export interface MarketplaceStats {
  totalListings: number;
  activeListings: number;
  totalSales: number;
  totalOffers: number;
  categoryCounts: Record<ListingCategory, number>;
  averagePrice: number;
  topCategories: { category: ListingCategory; count: number }[];
}
