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

module.exports = (sequelize) => {
  const PaymentMethod =   sequelize.define('PaymentMethod', {
        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,
        },
        name: {
            type: DataTypes.STRING(100),
            allowNull: false,
        },
        symbol: {
            type: DataTypes.STRING(20),
            allowNull: false,
        },
        type: {
            type: DataTypes.ENUM('crypto', 'fiat'),
            allowNull: false,
            defaultValue: 'fiat'
        },
        auto: {
            type: DataTypes.BOOLEAN,
            defaultValue: false
        },
        digit: {
            type: DataTypes.INTEGER,
            defaultValue: 2
        },
        details: {
            type: DataTypes.JSON
        },
        exchange: {
            type: DataTypes.BOOLEAN,
            defaultValue: false
        },
        depositCharge: {
            type: DataTypes.DECIMAL(30, 18)
        },
        minimum: {
            type: DataTypes.DECIMAL(30, 18)
        },
        maximum: {
            type: DataTypes.DECIMAL(30, 18)
        },
        qrCode: {
            type: DataTypes.BOOLEAN,
            defaultValue: false
        },
        config: {
            type: DataTypes.JSON
        },
        isActive: {
            type: DataTypes.BOOLEAN,
            defaultValue: true
        },
        showSupport: {
            type: DataTypes.BOOLEAN,
            defaultValue: false
        }
    }, {
        tableName: 'payment_methods',
        timestamps: true,
        underscored: true,
        createdAt: 'created_at',
        updatedAt: 'updated_at',
    }
    )

    return PaymentMethod
}