import {
  Column,
  CreateDateColumn,
  Entity,
  Index,
  ManyToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { SavingsAccount } from './savings-account.entity';

@Entity({ name: 'savings_transactions' })
export class SavingsTransaction {
  @PrimaryGeneratedColumn('uuid')
  id!: string;

  @Index()
  @Column({ type: 'varchar', name: 'account_id' })
  accountId!: string;

  @ManyToOne(() => SavingsAccount, (a) => a.transactions, { onDelete: 'CASCADE' })
  account?: SavingsAccount;

  @Column({ type: 'varchar', name: 'voucher_number', length: 30, nullable: true })
  voucherNumber?: string;

  @Column({ type: 'varchar', name: 'transaction_date', length: 20, nullable: true })
  transactionDate?: string;

  @Column({ type: 'varchar', name: 'transaction_date_bs', length: 20, nullable: true })
  transactionDateBs?: string;

  @Column({ type: 'varchar', name: 'type', length: 20, default: 'deposit' })
  type!: string;

  @Column({ name: 'amount', type: 'decimal', precision: 15, scale: 2 })
  amount!: number;

  @Column({ name: 'balance_after', type: 'decimal', precision: 15, scale: 2, default: 0 })
  balanceAfter!: number;

  @Column({ name: 'description', type: 'text', nullable: true })
  description?: string;

  @Column({ type: 'varchar', name: 'created_by', nullable: true })
  createdBy?: string;

  @CreateDateColumn({ name: 'created_at' })
  createdAt!: Date;

  @UpdateDateColumn({ name: 'updated_at' })
  updatedAt!: Date;
}
