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

export enum BalanceType {
    COMMISSION = 'COMMISSION',
    WITHDRAW = 'WITHDRAW',
    RETURN = 'RETURN'
}

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

    @Column()
    userId: number

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

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

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

    @Column({ type: 'enum', enum: BalanceType })
    type: BalanceType

    @Column({ nullable: true })
    remark: string

    @Column({ nullable: true })
    extra: string

    @CreateDateColumn()
    createdAt: Date

    constructor(record: Partial<BalanceRecord>) {
        Object.assign(this, record)
    }
}
