import { DataTypes, Model, Optional, Sequelize } from 'sequelize';

export interface CustomerAttributes extends Optional<CustomerInterface, 'id'> { }

export class Customer extends Model<CustomerInterface, CustomerAttributes> implements CustomerInterface {
    public id!: number;
    public userId!: number;
    public customerId!: string;
    public status!: number;
    public readonly createdAt!: Date;
    public readonly updatedAt!: Date;

    static initModel(sequelize: Sequelize): typeof Customer {
        Customer.init(
            {
                id: { type: DataTypes.BIGINT, autoIncrement: true, primaryKey: true, comment: "unique identifier" },
                userId: { type: DataTypes.BIGINT, allowNull: false, comment: "author of the record" },
                customerId: { type: DataTypes.STRING, allowNull: false, unique: "unique-customer", comment: "plan code" },
                status: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, comment: "User's Account status" }
            },
            { 
                paranoid: true, 
                underscored: true, 
                sequelize, 
                tableName: 'customers', 
                timestamps: true,
                indexes: [
                ]
            }
        );
        return Customer;
    }

    public static associate(models: any) {
        // Plan.hasOne(models.PlanContent, { foreignKey: 'planId', as: 'defaultContent' });
        // Plan.hasOne(models.PlanContent, { foreignKey: 'planId', as: 'content' });
        // Plan.hasOne(models.PlanContent, { foreignKey: 'planId', as: 'planContent' });
        // Plan.hasMany(models.PlanContent, { foreignKey: 'planId', as: 'planContents', onDelete: 'cascade', onUpdate: 'cascade' });
        // Plan.hasOne(models.Price, { foreignKey: 'planId', as: 'price' });
        // Plan.hasMany(models.Price, { foreignKey: 'planId', as: 'prices', onDelete: 'cascade', onUpdate: 'cascade' });
        // Plan.belongsTo(models.User, { foreignKey: 'userId', as: 'author' });
        // Plan.belongsTo(models.User, { foreignKey: 'lastUpdatedBy', as: 'updatedBy' });
    }
}
