/* eslint-disable @typescript-eslint/lines-between-class-members */
import { CreationOptional, DataTypes, InferAttributes, InferCreationAttributes, Model } from 'sequelize';

import { createIdGenerator } from '../../libs/util';

const nextId = createIdGenerator('ps', 24);

// eslint-disable-next-line prettier/prettier
export class PaymentStat extends Model<InferAttributes<PaymentStat>, InferCreationAttributes<PaymentStat>> {
  declare id: CreationOptional<string>;
  declare livemode: boolean;

  declare timestamp: number;
  declare currency_id: string;

  declare amount_paid: string;
  declare amount_payout: string;
  declare amount_refund: string;

  declare created_at: CreationOptional<Date>;
  declare updated_at: CreationOptional<Date>;

  public static readonly GENESIS_ATTRIBUTES = {
    id: {
      type: DataTypes.STRING(30),
      primaryKey: true,
      allowNull: false,
      defaultValue: nextId,
    },
    livemode: {
      type: DataTypes.BOOLEAN,
      allowNull: false,
    },
    timestamp: {
      type: DataTypes.INTEGER,
      defaultValue: 0,
    },
    currency_id: {
      type: DataTypes.STRING(16),
      allowNull: false,
    },
    amount_paid: {
      type: DataTypes.STRING(64),
      defaultValue: '0',
    },
    amount_payout: {
      type: DataTypes.STRING(64),
      defaultValue: '0',
    },
    amount_refund: {
      type: DataTypes.STRING(64),
      defaultValue: '0',
    },
    created_at: {
      type: DataTypes.DATE,
      defaultValue: DataTypes.NOW,
      allowNull: false,
    },
    updated_at: {
      type: DataTypes.DATE,
      defaultValue: DataTypes.NOW,
      allowNull: false,
    },
  };

  public static initialize(sequelize: any) {
    this.init(PaymentStat.GENESIS_ATTRIBUTES, {
      sequelize,
      modelName: 'PaymentStat',
      tableName: 'payment_stats',
      createdAt: 'created_at',
      updatedAt: 'updated_at',
    });
  }

  public static associate() {}
}

export type TPaymentStat = InferAttributes<PaymentStat>;
