import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Types } from 'mongoose';

@Schema({
    timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' },
})
export class Customer extends Document {
    @Prop({ type: String, required: true, trim: true })
    name: string;

    @Prop({ type: String, required: true })
    phone_no: string;

    @Prop({ type: String, default: '+91' })
    country_code: string;

    @Prop({ type: String, default: null, trim: true })
    email: string;

    @Prop({ type: String, default: null, trim: true })
    address: string;

    @Prop({ type: Types.ObjectId, ref: 'users', default: null })
    created_by: Types.ObjectId;
}

export const CustomerSchema = SchemaFactory.createForClass(Customer);
CustomerSchema.index({ country_code: 1, phone_no: 1 }, { unique: true });
