import { BigNumber } from 'bignumber.js'
import { DecimalTransformer } from '../../transformers/decimal.transformer'
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'

@Entity()
export class UserBalance {
    @PrimaryGeneratedColumn()
    id: number

    @Column({ unique: true })
    userId: number

    @Column({ type: 'decimal', precision: 19, scale: 2, transformer: new DecimalTransformer() })
    balance: BigNumber

    @Column({ type: 'decimal', precision: 19, scale: 2, transformer: new DecimalTransformer() })
    lastBalance: BigNumber

    @CreateDateColumn()
    createdAt: Date

    @UpdateDateColumn()
    updatedAt: Date

    constructor(userBalance: Partial<UserBalance>) {
        Object.assign(this, userBalance)
    }
}
