import { Router, Request, Response } from 'express';

const router = Router();

/**
 * GET /api/filters — Return all available Reonomy filter options as JSON.
 * This is a static reference for API consumers to know what they can pass to /api/scrape.
 */
router.get('/', (_req: Request, res: Response) => {
  return res.json({
    propertyTypes: [
      'Multifamily',
      'Multi Family (General)',
      'Multi Family (2-4 Units)',
      'Multi Family (5+ Units)',
      'Retail',
      'Office',
      'Industrial',
      'Hospitality',
      'Mixed Use',
      'Specialty',
      'Land',
      'Residential',
      'Single Family',
      'Condo',
      'Cooperative',
      'Garage/Parking',
      'Healthcare',
      'Religious',
      'Government',
      'Education',
    ],
    building: {
      yearBuiltFrom: { type: 'number', description: 'Minimum year built' },
      yearBuiltUntil: { type: 'number', description: 'Maximum year built' },
      yearRenovatedFrom: { type: 'number', description: 'Minimum year renovated' },
      yearRenovatedUntil: { type: 'number', description: 'Maximum year renovated' },
      zoning: { type: 'string', description: 'Zoning code' },
      lotSizeSfMin: { type: 'number', description: 'Minimum lot size in SF' },
      lotSizeSfMax: { type: 'number', description: 'Maximum lot size in SF' },
      lotSizeAcresMin: { type: 'number', description: 'Minimum lot size in acres' },
      lotSizeAcresMax: { type: 'number', description: 'Maximum lot size in acres' },
      opportunityZone: { type: 'boolean', description: 'In opportunity zone' },
      totalUnitsMin: { type: 'number', description: 'Minimum total units' },
      totalUnitsMax: { type: 'number', description: 'Maximum total units' },
      buildingAreaMin: { type: 'number', description: 'Minimum building area SF' },
      buildingAreaMax: { type: 'number', description: 'Maximum building area SF' },
    },
    owner: {
      nameOrCompany: { type: 'string', description: 'Owner name or company' },
      ownerType: { type: 'enum', values: ['Company', 'Person'] },
      includesPhone: { type: 'boolean', description: 'Owner has phone on file' },
      includesEmail: { type: 'boolean', description: 'Owner has email on file' },
      includesMailingAddress: { type: 'boolean', description: 'Owner has mailing address' },
      portfolioMin: { type: 'number', description: 'Minimum portfolio size' },
      portfolioMax: { type: 'number', description: 'Maximum portfolio size' },
      ownerOccupied: { type: 'boolean', description: 'Owner occupied only' },
      inStateOwner: { type: 'boolean', description: 'In-state owner only' },
      portfolioValueMin: { type: 'number', description: 'Minimum portfolio value' },
      portfolioValueMax: { type: 'number', description: 'Maximum portfolio value' },
    },
    sales: {
      dateRange: { type: 'string', description: 'Sale date range' },
      multiParcel: { type: 'boolean', description: 'Multi-parcel sales only' },
      priceMin: { type: 'number', description: 'Minimum sale price' },
      priceMax: { type: 'number', description: 'Maximum sale price' },
      pricePerSfMin: { type: 'number', description: 'Minimum price per SF' },
      pricePerSfMax: { type: 'number', description: 'Maximum price per SF' },
      likelyToSell: { type: 'boolean', description: 'Likely to sell indicator' },
    },
    debt: {
      amountMin: { type: 'number', description: 'Minimum debt amount' },
      amountMax: { type: 'number', description: 'Maximum debt amount' },
      originationFrom: { type: 'string', description: 'Origination date from' },
      originationUntil: { type: 'string', description: 'Origination date until' },
      maturityFrom: { type: 'string', description: 'Maturity date from' },
      maturityUntil: { type: 'string', description: 'Maturity date until' },
      lenderName: { type: 'string', description: 'Lender name' },
      cmbsLoan: { type: 'boolean', description: 'CMBS loan only' },
    },
    distressed: {
      auctionDateFrom: { type: 'string', description: 'Auction date from' },
      auctionDateUntil: { type: 'string', description: 'Auction date until' },
      preForeclosureCategory: { type: 'string', description: 'Pre-foreclosure category' },
      cmbsWatchlist: { type: 'boolean', description: 'CMBS watchlist only' },
    },
    outputFields: {
      propertyInfo: ['address', 'type', 'units', 'sqft', 'yearBuilt', 'lotSize', 'zoning', 'opportunityZone', 'apn', 'legal'],
      ownerInfo: ['name', 'company', 'portfolioSize', 'portfolioValue', 'ownerType'],
      contactInfo: ['phones', 'emails'],
      salesInfo: ['lastSaleDate', 'lastSalePrice', 'buyer', 'seller', 'deedType'],
      debtInfo: ['lender', 'loanType', 'mortgageAmount', 'maturityDate', 'interestType'],
      taxInfo: ['assessedValue', 'taxAmount'],
    },
  });
});

export default router;
