import { FindPlansParams, IPlansAdapter, IPlan } from "./Plans.interface";
import { Document, Model, Schema, model } from "mongoose";

export interface IPlanDocument extends Omit<IPlan, "id">, Document {}

export class PlansAdapterMongoose implements IPlansAdapter {
    schema: Schema;
    planList: Model<IPlanDocument>;

    constructor() {
        this.schema = new Schema({
            name: { type: String, required: true, unique: true },
            description: { type: String, required: true },
            features: { type: Array, required: true, default: [] },
            code: { type: String, required: true, unique: true },
            price: { type: Number, required: true },
            annualPrice: { type: Number, required: true },
            limitOrganizations: { type: Number, required: true },
            limitEmployees: { type: Number, required: true },
            limitServices: { type: Number, required: true },
            limitAppointments: { type: Number, required: true },
            limitClients: { type: Number, required: true },
            limitRepeats: { type: Number, required: true },
            mailNotifications: { type: Boolean, required: true },
            smsNotifications: { type: Boolean, required: true },
            wapNotifications: { type: Boolean, required: true },
            payments: { type: Boolean, required: false },
            bot: { type: Boolean, required: true },
            active: { type: Boolean, required: true },
            mpPlanId: { type: String, required: false },
            dateLimit: { type: Boolean, required: true },
            discount3Months: { type: Number, required: false },
            discount6Months: { type: Number, required: false },
            discount12Months: { type: Number, required: false },
            featured: { type: Boolean, required: false },
        });

        this.planList = model<IPlanDocument>("Plan", this.schema);
    }

    public async find(filters: FindPlansParams): Promise<IPlan[]> {
        return this.planList.find(filters).exec();
    }

    public async findOne(filters: FindPlansParams): Promise<IPlanDocument | null> {
        return this.planList.findOne(filters).exec();
    }
}
