import { FindProvinciasParams, IProvinciasAdapter, IProvincia } from "./Provincias.interface";
import { Document, Model, Schema, model } from "mongoose";

export interface IProvinciaDocument extends Omit<IProvincia, "id">, Document {}

export class ProvinciasAdapterMongoose implements IProvinciasAdapter {
    schema: Schema;
    provinciaList: Model<IProvinciaDocument>;

    constructor() {
        this.schema = new Schema({
            name: { type: String, required: true, unique: true },
            code: { type: Number, required: true, default: 0 },
        });

        this.provinciaList = model<IProvinciaDocument>("Provincia", this.schema);
    }

    public async find(filters: FindProvinciasParams): Promise<IProvincia[]> {
        return await this.provinciaList.find(filters).exec();
    }
}
