import type { Inquiry, InquiryStatus, InquiryKind, InquiryMessage, Attachment } from '../domain/inquiry'

export interface InquiryFilters {
  status?: InquiryStatus
  propertyId?: string
  organizationId?: string   // Supply-Perspektive
  tenantOrgId?: string      // Demand-Perspektive
  kind?: InquiryKind
}

/** Demand→Supply: neue Anfrage zu einem Objekt. */
export interface CreateInquiryInput {
  organizationId: string    // Supply-Org (Objekt-Eigentümer)
  tenantOrgId: string       // Demand-Org (Absender)
  propertyId: string
  needId?: string
  tenantName: string
  tenantCompany?: string
  tenantEmail?: string
  propertyAddress?: string
  subject: string
  message: string
  matchScore?: number
}

/** Supply→Demand: Angebot zu einem latenten Bedarf. */
export interface CreateOfferInput {
  organizationId: string    // Supply-Org (Absender)
  tenantOrgId: string       // Demand-Org (Empfänger, aus need.organizationId)
  needId: string
  propertyId: string        // primäres Objekt (Kompatibilität)
  offeredPropertyIds: string[]
  subject: string
  message: string
  senderName: string        // Verwaltungs-/Org-Name
  recipientName?: string
  attachments?: Attachment[]
}

export interface IInquiryProvider {
  getAll(filters?: InquiryFilters): Promise<Inquiry[]>
  getById(id: string): Promise<Inquiry | null>
  createInquiry(input: CreateInquiryInput): Promise<Inquiry>
  createOffer(input: CreateOfferInput): Promise<Inquiry>
  updateStatus(id: string, status: InquiryStatus): Promise<Inquiry>
  markThreadAsRead(id: string): Promise<Inquiry>
  getUnreadCount(filters?: InquiryFilters): Promise<number>
  addMessage(
    inquiryId: string,
    msg: Omit<InquiryMessage, 'id' | 'inquiryId' | 'createdAt'>,
  ): Promise<Inquiry>
}
