const { DataTypes } = require("sequelize")
const { generateRandomString } = require("../utils/helpers")

module.exports = (sequelize) => {
  const WithdrawalMethod =   sequelize.define('WithdrawalMethod', {
        id: {
            type: DataTypes.BIGINT.UNSIGNED,
            allowNull: false,
            autoIncrement: true,
            primaryKey: true
        },
        reference: {
            type: DataTypes.STRING(20),
            allowNull: false,
            defaultValue: () => generateRandomString(16)
        },
        slug: {
            type: DataTypes.STRING(40),
            allowNull: false,
        },
        logo: {
            type: DataTypes.STRING(200),
            allowNull: false,
        },
        type: {
            type: DataTypes.ENUM('crypto', 'fiat'),
            allowNull: false,
            defaultValue: 'fiat'
        },
        name: {
            type: DataTypes.STRING(100),
            allowNull: false,
        },
        symbol: {
            type: DataTypes.STRING(20),
            allowNull: false,
        },
        
        minimum: {
            type: DataTypes.DECIMAL(30, 18)
        },
        maximum: {
            type: DataTypes.DECIMAL(30, 18)
        },
        chargesFixed: {
            type: DataTypes.DECIMAL(20, 4),
            field: 'charges_fixed'
        },
        chargesPercentage: {
            type: DataTypes.DECIMAL(20, 4),
            field: 'charges_percentage'
        },
        duration: {
            type: DataTypes.STRING(50),
            allowNull: false,
        },
        isActive: {
            type: DataTypes.BOOLEAN,
            defaultValue: true
        }
    }, {
        tableName: 'withdrawal_methods',
        timestamps: true,
        underscored: true,
        createdAt: 'created_at',
        updatedAt: 'updated_at',
    }
    )

    return WithdrawalMethod
}