import { Schema, model, Document, Types } from 'mongoose'

const SubCommunitySchema = new Schema(
	{
		community: {
			type: Types.ObjectId,
			ref: 'Community',
			required: true,
		},
		name: {
			type: String,
			required: true
		},
		isCourse: Boolean
	},
	{ versionKey: false }
)

SubCommunitySchema.index({ community: 1, name: 1 }, { unique: true })

export interface ISubCommunity extends Document {
	_id: Types.ObjectId
	community: Types.ObjectId
	name: String
	isCourse?: boolean
}

export const SubCommunity = model('SubCommunity', SubCommunitySchema, 'sub-communities')
