import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Types, HydratedDocument } from 'mongoose';
import moment from 'moment';
import { KnowledgeBase } from './knowledge_base.schema';
import { Workspace } from './workspace.model';
import { Users } from './user.schema';
import { TwilioConfig } from './twilio.config';

export enum AgentStatus {
    ACTIVE = "ACTIVE",
    IN_ACTIVE = "IN_ACTIVE",
}

@Schema()
export class Agents extends Document {

    @Prop({ type: String, enum:["ADMIN_AGENT", "VENDOR_AGENT"] , default: "VENDOR_AGENT" })
    agent_type: string

    @Prop({ type: Types.ObjectId, ref: TwilioConfig.name, default: null })
    twilio_config: Types.ObjectId;

    @Prop({ type: [Types.ObjectId], ref: KnowledgeBase.name, default: [] })
    knowledge_base_id: Types.ObjectId[]

    @Prop({ type: [String], ref: KnowledgeBase.name, default: [] })
    knowledge_base_id_for_website: string[]

    @Prop({ type: Types.ObjectId, ref: Workspace.name, default: null })
    workspace_id: Types.ObjectId

    @Prop({ type: String, default: null })
    name: string = null

    @Prop({ type: String, default: null })
    type: string = null

    @Prop({ type: String, default: null })
    image: string = null

    @Prop({ type: String, default: null })
    phone_no: string = null

    @Prop({ type: String, default: null })
    country_code: string = null

    @Prop({ type: String, default: "" })
    call_prompt: string;

    @Prop({ type: String, default: "" })
    call_first_message: string;

    @Prop({ type: String, default: "" })
    chat_prompt: string;

    @Prop({ type: String, default: "" })
    chat_first_message: string;

    @Prop({ type: String, default: null })
    voice: string = null

    @Prop({ type: String, default: null })
    ai_model: string = null

    @Prop({ type: String, default: null })
    ai_model_version: string = null

    @Prop({ type: Boolean, default: false })
    idle_reminder: boolean

    @Prop({ type: Boolean, default: false })
    call_cut_ability: boolean

    @Prop({ type: String, default: null })
    call_limit_duration: string = null

    @Prop({ type: Boolean, default: false })
    call_transfer: boolean

    @Prop({ type: Boolean, default: false })
    send_message: boolean

    @Prop({ type: Boolean, default: false })
    real_time_booking: boolean

    @Prop({ type: Boolean, default: false })
    is_default: boolean

    @Prop({ type: String })
    default_type: string

    @Prop({ type: Types.ObjectId, ref: Users.name, default: null })
    created_by: Types.ObjectId = null

    @Prop({ type: String, enum: AgentStatus, default: AgentStatus.ACTIVE })
    status: string;

    @Prop({ type: Boolean, default: false })
    is_deleted: boolean

    @Prop({ default: moment().utc().valueOf() })
    created_at: number = moment().utc().valueOf();

    @Prop({ default: moment().utc().valueOf() })
    updated_at: number = moment().utc().valueOf();
}

export const agentSchema = SchemaFactory.createForClass(Agents);