const mongoose = require('mongoose');

const cityTaxiSchema = new mongoose.Schema({
    cityName: {
        type: String,
        required: [true, 'City name is required'],
        trim: true,
        unique: true
    },
    // KEEPING GEOJSON FORMAT - DO NOT CHANGE
    coordinates: {
        type: { type: String, enum: ['Point'], default: 'Point' },
        coordinates: { type: [Number], default: [0, 0] } // [longitude, latitude]
    },
    slug: {
        type: String,
        unique: true,
        lowercase: true,
        trim: true
    },
    zone: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Zone',
        required: [true, 'Zone is required for pricing calculation']
    },

    // --- NEW SEO CONTENT FIELDS (Safe to add) ---
    metaTitle: {
        type: String,
        trim: true
    },
    metaDescription: {
        type: String,
        trim: true
    },
    pageContent: {
        type: String,
        default: '' // HTML description for the city page
    },
    faqs: [{
        question: String,
        answer: String
    }],
    popularPlaces: [{ // For "Things to do" section
        name: String,
        description: String,
        imageUrl: String
    }],
    // --------------------------------------------

    displayOrder: {
        type: Number,
        default: 0
    },
    isActive: {
        type: Boolean,
        default: true,
        index: true
    },
    createdBy: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'User'
    }
}, { timestamps: true });

// Auto-generate slug before saving
cityTaxiSchema.pre('save', function (next) {
    if (!this.slug || this.isModified('cityName')) {
        const city = this.cityName.toLowerCase().replace(/\s+/g, '-');
        this.slug = `${city}-taxi-services`;
    }
    next();
});

cityTaxiSchema.index({ displayOrder: 1 });

module.exports = mongoose.model('CityTaxi', cityTaxiSchema);