import mongoose, { Document, Schema } from 'mongoose';

export interface IPayment extends Document {
    userId: mongoose.Types.ObjectId;
    sessionId: string;
    paymentIntentId?: string;
    amount: number;
    currency: string;
    status: 'created' | 'succeeded' | 'failed';
    provider: 'stripe';
    metadata?: Record<string, any>;
    createdAt: Date;
    updatedAt: Date;
}

const paymentSchema = new Schema<IPayment>({
    userId: { type: Schema.Types.ObjectId, ref: 'User', required: true },
    sessionId: { type: String, required: true, unique: true },
    paymentIntentId: { type: String },
    amount: { type: Number, required: true },
    currency: { type: String, required: true },
    status: {
        type: String,
        enum: ['created', 'succeeded', 'failed'],
        default: 'created'
    },
    provider: {
        type: String,
        enum: ['stripe'],
        default: 'stripe'
    },
    metadata: { type: Map, of: Schema.Types.Mixed }
}, { timestamps: true });

export default mongoose.model<IPayment>('Payment', paymentSchema);
