export default (sequelize, DataTypes) => {
    return sequelize.define('ClientManagement', {
        id: {
            type: DataTypes.INTEGER,
            primaryKey: true,
            autoIncrement: true
        },
        name: {
            type: DataTypes.STRING(100),
            allowNull: false,
            validate: {
                notEmpty: { msg: "Name is required" },
                noDigits(value) {
                    if (/\d/.test(value)) {
                        throw new Error("Name must not contain numbers");
                    }
                }
            },
        },
        email: {
            type: DataTypes.STRING(150),
            allowNull: false,
            validate: {
                isEmail: { msg: "Please provide a valid email address" },
                notEmpty: { msg: "Email is required" }
            },
        },
        phone: {
            type: DataTypes.STRING(20),
            allowNull: false,
            validate: {
                notEmpty: { msg: "Phone number is required" },
                isValidPhone(value) {
                    if (!/^\d{5}\d{5}$/.test(value)) {
                        throw new Error("Phone must be in format: +91 XXXXX XXXXX");
                    }
                }
            },
        },
       date : {
        type: DataTypes.DATEONLY,
        allowNull: false,
         },
         source: {
            type: DataTypes.STRING(50),
            allowNull: false,
            validate: { 
                notEmpty: { msg: "Source is required" },
                isIn: {
                    args: [["Referral", "Website", "Social Media", "Email Campaign", "Other"]],
                    msg: "Source must be one of: Referral, Website, Social Media, Email Campaign, Other"
                }
            },  
        },
        amount:{   
            type: DataTypes.DECIMAL(10, 2),
            allowNull: false,
            validate: {
                
                notEmpty: { msg: "Amount is required" },
                isDecimal: { msg: "Amount must be a decimal number" },
                min: {
                    args: [0],
                    msg: "Amount must be a positive number"
                }
            }   
        },
        text_area: {
            type: DataTypes.STRING(255),
            allowNull: true,       
    },
},
        {
        tableName: 'client_management',
        timestamps: false,
    });
};


