'use strict';
const {
  Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
  class PaymentMethod extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      // define association here
    }
  }
 PaymentMethod.init({
  userId: {
    type: DataTypes.INTEGER,
    allowNull: false
  },
  type: {
    type: DataTypes.ENUM(
      'credit_card',
      'debit_card',
      'paypal',
      'bank_transfer',
      'mobile_money',
      'cash_on_delivery'
    ),
    allowNull: false
  },
  provider: DataTypes.STRING,
  token: {
    type: DataTypes.STRING,
    allowNull: true
  },
  last4: DataTypes.STRING,
  expiryMonth: {
    type: DataTypes.INTEGER,
    validate: {
      min: 1,
      max: 12
    }
  },
  expiryYear: {
    type: DataTypes.INTEGER,
    validate: {
      min: 2024
    }
  },
  isDefault: {
    type: DataTypes.BOOLEAN,
    defaultValue: false
  }
}, {
  sequelize,
  modelName: 'PaymentMethod',
});
  return PaymentMethod;
};