import mongoose, { type InferSchemaType } from 'mongoose'

const userSchema = new mongoose.Schema(
  {
    name: { type: String, required: true, trim: true, maxlength: 80 },
    email: { type: String, required: true, unique: true, lowercase: true, trim: true },
    passwordHash: { type: String },
    avatar: { type: String },
    googleId: { type: String, index: true, sparse: true },
    refreshTokenHash: { type: String },
  },
  { timestamps: { createdAt: true, updatedAt: true } },
)

export type UserDocument = InferSchemaType<typeof userSchema> & { _id: mongoose.Types.ObjectId }

export const User = mongoose.model('User', userSchema)
