import { Document, Model, Schema, model } from "mongoose";
import {
    CreateSchedulesDisabledParams,
    FindSchedulesDisabledParams,
    ISchedulesDisabled,
    ISchedulesDisabledAdapter,
} from "./SchedulesDisabled.Interface";

export interface ISchedulesDisabledDocument extends Omit<ISchedulesDisabled, "id ">, Document {}

export class SchedulesDisabledAdapterMongoose implements ISchedulesDisabledAdapter {
    schema: Schema;
    schedulesDisabledList: Model<ISchedulesDisabledDocument>;

    constructor() {
        this.schema = new Schema({
            employeeId: { type: Schema.Types.ObjectId, required: true, ref: "Employee" },
            companyId: { type: Schema.Types.ObjectId, required: true, ref: "Companie" },
            startDate: { type: Date, required: true },
            endDate: { type: Date, required: true },
            creationDate: { type: Date, required: true, default: Date.now },
        });

        this.schedulesDisabledList = model<ISchedulesDisabledDocument>("SchedulesDisabled", this.schema);
    }

    public async create(data: CreateSchedulesDisabledParams): Promise<ISchedulesDisabled> {
        return await this.schedulesDisabledList.create(data);
    }

    public async delete(id: string): Promise<void> {
        await this.schedulesDisabledList.deleteOne({ _id: id }).exec();
    }

    public async findOne(
        filters: Omit<FindSchedulesDisabledParams, "sessionUser">
    ): Promise<ISchedulesDisabledDocument | null> {
        return this.schedulesDisabledList.findOne(filters).exec();
    }
}
