export default (sequelize, DataTypes) => {
    return sequelize.define('Invoice', {
        id: {
            type: DataTypes.INTEGER,
            primaryKey: true,
            autoIncrement: true
        },
        invoice_number: {
            type: DataTypes.STRING,
            allowNull: false,
            unique: true
        },
        date: {
            type: DataTypes.DATEONLY,
            allowNull: false,
            defaultValue: DataTypes.NOW
        },
        client_name: {
            type: DataTypes.STRING,
            allowNull: false
        },
        client_email: {
            type: DataTypes.STRING,
            allowNull: true,
            validate: {
                isEmail: true
            }
        },
        address: {
            type: DataTypes.STRING,
            allowNull: true
        },
        phone: {
            type: DataTypes.STRING,
            allowNull: true
        },
        gst_in: {
            type: DataTypes.STRING,
            allowNull: true
        },
        sac_code: {
            type: DataTypes.STRING,
            allowNull: true
        },
        amount_details: {
            type: DataTypes.STRING,
            allowNull: true
        },
        gst_percent: {
            type: DataTypes.DECIMAL(5, 2),
            allowNull: true,
            defaultValue: 0
        },
        status: {
            type: DataTypes.STRING,
            allowNull: false,
            defaultValue: 'pending'
        },
       total_amount: {
            type: DataTypes.DECIMAL(10, 2),
            allowNull: false,
            defaultValue: 0
        },
        amount: {   
            type: DataTypes.DECIMAL(10, 2),
            allowNull: false,
            defaultValue: 0
        },
        owner_signature: {
            type: DataTypes.STRING,
            allowNull: false
        },
        items: {
            type: DataTypes.JSON,
            allowNull: true
        },
        description: {
            type: DataTypes.TEXT,
            allowNull: true
        },
        created_at: {
            type: DataTypes.DATE,
            allowNull: false,
            defaultValue: DataTypes.NOW
        }
    }, {
        tableName: 'invoices',
        timestamps: false
    });
};
