import { Entity, Column, Index, ManyToOne, JoinColumn } from 'typeorm';
import { BaseEntity } from '../database/base.entity';
import { BankEntity } from './bank.entity';

/**
 * Bank Account entity — tenant-scoped company bank accounts.
 *
 * Linked to Bank Master via `bank_id`. CIN / PAN / GST are optional
 * legal identifiers stored on the account (not the bank name).
 */
@Entity('bank_accounts')
@Index(['tenant_id', 'is_deleted'])
@Index(['tenant_id', 'bank_id'])
export class BankAccountEntity extends BaseEntity {
  @ManyToOne(() => BankEntity, (bank) => bank.accounts, { nullable: false })
  @JoinColumn({ name: 'bank_id' })
  bank: BankEntity;

  @Column({ type: 'uuid' })
  bank_id: string;

  @Column({ type: 'varchar', length: 255 })
  account_name: string;

  @Column({ type: 'varchar', length: 21, nullable: true })
  cin: string | null;

  @Column({ type: 'varchar', length: 10, nullable: true })
  pan: string | null;

  @Column({ type: 'varchar', length: 15, nullable: true })
  gst: string | null;

  @Column({ type: 'boolean', default: true })
  is_active: boolean;
}
