import { db } from "../server/db";
import { apartments, petServices } from "../shared/schema";

async function seedDatabase() {
  console.log("Seeding database...");
  
  try {
    // NYC coordinates
    const nycLat = 40.7128;
    const nycLng = -74.0060;
    
    // Demo apartments
    const demoApartments = [
      {
        title: "Modern Midtown Apartment",
        address: "123 East 53rd St",
        city: "New York",
        state: "NY",
        zipCode: "10022",
        neighborhood: "Midtown East",
        price: 1650,
        bedrooms: 1,
        bathrooms: 1,
        squareFeet: 750,
        petDeposit: 300,
        latitude: nycLat + 0.01,
        longitude: nycLng + 0.008,
        imageUrl: "https://images.unsplash.com/photo-1560448204-e02f11c3d0e2?w=800&h=500&fit=crop",
        rating: 4.8,
        reviewCount: 24,
        description: "Bright and modern apartment in Midtown East with hardwood floors and great natural light.",
        isPetFriendly: true,
        dogFriendly: true,
        catFriendly: true,
        otherPetsFriendly: false,
        petAmenities: ["Dog Park 0.2 mi", "Pet Washing Station", "Vet Clinic 0.5 mi"],
      },
      {
        title: "Luxury Downtown Loft",
        address: "45 Wall Street",
        city: "New York",
        state: "NY",
        zipCode: "10005",
        neighborhood: "Financial District",
        price: 2100,
        bedrooms: 2,
        bathrooms: 2,
        squareFeet: 950,
        petDeposit: 500,
        latitude: nycLat - 0.02,
        longitude: nycLng + 0.01,
        imageUrl: "https://images.unsplash.com/photo-1481253127861-534498168948?w=800&h=500&fit=crop",
        rating: 4.6,
        reviewCount: 18,
        description: "Spacious downtown loft with city views, high ceilings, and luxury amenities.",
        isPetFriendly: true,
        dogFriendly: true,
        catFriendly: false,
        otherPetsFriendly: false,
        petAmenities: ["Dog Run on Roof", "Pet Store 0.1 mi", "Dog Walkers Included"],
      },
      {
        title: "Cozy Brooklyn Studio",
        address: "78 Bedford Ave",
        city: "Brooklyn",
        state: "NY",
        zipCode: "11211",
        neighborhood: "Williamsburg",
        price: 1900,
        bedrooms: 0,
        bathrooms: 1,
        squareFeet: 550,
        petDeposit: 0,
        latitude: nycLat - 0.01,
        longitude: nycLng + 0.03,
        imageUrl: "https://images.unsplash.com/photo-1512917774080-9991f1c4c750?w=800&h=500&fit=crop",
        rating: 4.9,
        reviewCount: 32,
        description: "Charming studio apartment in trendy Williamsburg with modern finishes.",
        isPetFriendly: true,
        dogFriendly: true,
        catFriendly: true,
        otherPetsFriendly: true,
        petAmenities: ["Dog Park Across Street", "3 Vets Within 0.5 mi", "Pet Meetups Monthly"],
      }
    ];
    
    // Demo pet services
    const demoPetServices = [
      {
        name: "Central Park Dog Run",
        type: "dog_park",
        address: "85th Street Transverse",
        city: "New York",
        state: "NY",
        zipCode: "10028",
        latitude: nycLat + 0.015,
        longitude: nycLng + 0.012,
        imageUrl: "https://images.unsplash.com/photo-1550137212-33cce0250053?w=800&h=500&fit=crop",
        website: "https://www.centralparknyc.org/locations/dog-runs",
        phone: "212-555-1234",
      },
      {
        name: "Manhattan Veterinary Clinic",
        type: "vet",
        address: "223 W 83rd St",
        city: "New York",
        state: "NY",
        zipCode: "10024",
        latitude: nycLat + 0.008,
        longitude: nycLng + 0.005,
        imageUrl: "https://images.unsplash.com/photo-1532629345422-7515f3d16bb6?w=800&h=500&fit=crop",
        website: "https://manhattanvet.com",
        phone: "212-555-2345",
      },
      {
        name: "PetSmart - Brooklyn",
        type: "pet_store",
        address: "238 Atlantic Ave",
        city: "Brooklyn",
        state: "NY",
        zipCode: "11201",
        latitude: nycLat - 0.015,
        longitude: nycLng + 0.02,
        imageUrl: "https://images.unsplash.com/photo-1583337130417-3346a1be7dee?w=800&h=500&fit=crop",
        website: "https://www.petsmart.com",
        phone: "718-555-3456",
      },
      {
        name: "East Village Animal Hospital",
        type: "vet",
        address: "150 E 2nd St",
        city: "New York",
        state: "NY",
        zipCode: "10009",
        latitude: nycLat - 0.005,
        longitude: nycLng + 0.018,
        imageUrl: "https://images.unsplash.com/photo-1581888227599-779811939961?w=800&h=500&fit=crop",
        website: "https://eastvillagevet.com",
        phone: "212-555-4567",
      },
      {
        name: "Tompkins Square Dog Run",
        type: "dog_park",
        address: "E 9th St",
        city: "New York",
        state: "NY",
        zipCode: "10009",
        latitude: nycLat - 0.003,
        longitude: nycLng + 0.022,
        imageUrl: "https://images.unsplash.com/photo-1548658166-136d9f6a7e76?w=800&h=500&fit=crop",
        website: "https://www.nycgovparks.org/parks/tompkins-square-park/highlights/12399",
        phone: "212-555-5678",
      }
    ];
    
    // Insert apartments
    for (const apartment of demoApartments) {
      await db.insert(apartments).values(apartment);
    }
    console.log(`Added ${demoApartments.length} apartments`);
    
    // Insert pet services
    for (const service of demoPetServices) {
      await db.insert(petServices).values(service);
    }
    console.log(`Added ${demoPetServices.length} pet services`);
    
    console.log("Database seeding completed successfully!");
  } catch (error) {
    console.error("Error seeding database:", error);
  } finally {
    process.exit(0);
  }
}

seedDatabase();