import { Column, Entity, JoinColumn, ManyToOne, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { BankAccountEntity } from './bank-account.entity';
import { PaydayRewardEntity } from './payday-reward.entity';

@Entity('bank_transactions')
export class BankTransactionEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column() bank_account_id: number;
    @Column({ type: 'int', nullable: true }) counter_bank_account_id: number | null;
    @Column({ type: 'varchar', length: 64 }) counter_name: string;
    @Column() amount: number;
    @Column({ type: 'varchar', length: 64 }) reason: string;
    @Column({ type: 'varchar', length: 128 }) description: string;
    @Column({ type: 'varchar', length: 16 }) type: string;
    @Column({ type: 'varchar', length: 32 }) category: string;
    @Column({ type: 'binary', length: 32 }) ref: string;
    @Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) date: string;

    @ManyToOne(() => BankAccountEntity, (bankAccount) => bankAccount.transactions)
    @JoinColumn({ name: 'bank_account_id' })
    bankAccount: BankAccountEntity;

    @ManyToOne(() => BankAccountEntity, (bankAccount) => bankAccount.transactions)
    @JoinColumn({ name: 'counter_bank_account_id' })
    counterBankAccount: BankAccountEntity;

    @OneToMany(() => PaydayRewardEntity, (reward) => reward.bankTransaction)
    paydayRewards: PaydayRewardEntity[];
}
