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

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

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

export class RevenueSnapshot extends Model<InferAttributes<RevenueSnapshot>, InferCreationAttributes<RevenueSnapshot>> {
  declare id: CreationOptional<string>;
  declare livemode: boolean;
  declare currency_id: string;

  declare timestamp: number;
  declare period_type: 'monthly' | 'quarterly';

  declare total_revenue: string;
  declare refund_amount: string;
  declare promotion_cost: string;
  declare credit_grant_cost: string;
  declare vendor_cost: string;
  declare taxed_revenue: string;
  declare net_revenue: string;

  declare archive_metadata_id: CreationOptional<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,
    },
    currency_id: {
      type: DataTypes.STRING(16),
      allowNull: false,
    },
    timestamp: {
      type: DataTypes.INTEGER,
      allowNull: false,
    },
    period_type: {
      type: DataTypes.ENUM('monthly', 'quarterly'),
      allowNull: false,
      defaultValue: 'monthly',
    },
    total_revenue: {
      type: DataTypes.STRING(64),
      defaultValue: '0',
    },
    refund_amount: {
      type: DataTypes.STRING(64),
      defaultValue: '0',
    },
    promotion_cost: {
      type: DataTypes.STRING(64),
      defaultValue: '0',
    },
    credit_grant_cost: {
      type: DataTypes.STRING(64),
      defaultValue: '0',
    },
    vendor_cost: {
      type: DataTypes.STRING(64),
      defaultValue: '0',
    },
    taxed_revenue: {
      type: DataTypes.STRING(64),
      defaultValue: '0',
    },
    net_revenue: {
      type: DataTypes.STRING(64),
      defaultValue: '0',
    },
    archive_metadata_id: {
      type: DataTypes.STRING(40),
      allowNull: true,
    },
    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(RevenueSnapshot.GENESIS_ATTRIBUTES, {
      sequelize,
      modelName: 'RevenueSnapshot',
      tableName: 'revenue_snapshots',
      createdAt: 'created_at',
      updatedAt: 'updated_at',
    });
  }

  public static associate() {}
}

export type TRevenueSnapshot = InferAttributes<RevenueSnapshot>;
