"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const sequelize_1=require("sequelize");class ecommerceCategory extends sequelize_1.Model{static initModel(e){return ecommerceCategory.init({id:{type:sequelize_1.DataTypes.UUID,defaultValue:sequelize_1.DataTypes.UUIDV4,primaryKey:!0,allowNull:!1},name:{type:sequelize_1.DataTypes.STRING(191),allowNull:!1,validate:{notEmpty:{msg:"name: Name must not be empty"}}},slug:{type:sequelize_1.DataTypes.STRING(191),allowNull:!1,validate:{notEmpty:{msg:"slug: Slug must not be empty"}}},description:{type:sequelize_1.DataTypes.STRING(191),allowNull:!1,validate:{notEmpty:{msg:"description: Description must not be empty"}}},image:{type:sequelize_1.DataTypes.STRING(191),allowNull:!0,validate:{is:{args:["^/(uploads|img)/.*$","i"],msg:"image: Image must be a valid URL"}}},status:{type:sequelize_1.DataTypes.BOOLEAN,allowNull:!1,defaultValue:!0,validate:{isBoolean:{msg:"status: Status must be a boolean value"}}}},{sequelize:e,modelName:"ecommerceCategory",tableName:"ecommerce_category",timestamps:!0,paranoid:!0,indexes:[{name:"PRIMARY",unique:!0,using:"BTREE",fields:[{name:"id"}]}],hooks:{async beforeValidate(e){!e.slug&&e.name&&(e.slug=await ecommerceCategory.generateUniqueSlug(e.name))}}})}static associate(e){ecommerceCategory.hasMany(e.ecommerceProduct,{as:"ecommerceProducts",foreignKey:"categoryId",onDelete:"CASCADE",onUpdate:"CASCADE"})}static async generateUniqueSlug(e){const a=e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");let t=a,s=1;for(;await ecommerceCategory.findOne({where:{slug:t}});){t=`${a}-${s}`;s++}return t}}exports.default=ecommerceCategory;