import { db } from "../../db/postgre.js";
import { Plan } from "../entities/plan.js";
export const PlanRepository = db.getRepository(Plan).extend({
    pack (src) {
        return Promise.resolve().then(async ()=>{
            const plan = typeof src === "object" ? src : await this.findOneByOrFail({
                id: src
            });
            return {
                id: plan.id,
                createdAt: plan.createdAt.toISOString(),
                updatedAt: plan.updatedAt?.toISOString() ?? null,
                name: plan.name,
                icon: plan.icon,
                description: plan.description
            };
        });
    },
    packMany (plans) {
        return Promise.all(plans.map((x)=>this.pack(x)));
    }
});
