/**
 * Partner Bank Account Entity
 * Cuentas bancarias asociadas a partners
 *
 * @module Partners
 * @table partners.partner_bank_accounts
 */

import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  Index,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { Partner } from './partner.entity';

@Entity({ name: 'partner_bank_accounts', schema: 'partners' })
export class PartnerBankAccount {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Index()
  @Column({ name: 'partner_id', type: 'uuid' })
  partnerId: string;

  @ManyToOne(() => Partner, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'partner_id' })
  partner: Partner;

  // Banco
  @Column({ name: 'bank_name', type: 'varchar', length: 100 })
  bankName: string;

  @Column({ name: 'bank_code', type: 'varchar', length: 10, nullable: true })
  bankCode: string;

  // Cuenta
  @Column({ name: 'account_number', type: 'varchar', length: 30 })
  accountNumber: string;

  @Column({ type: 'varchar', length: 20, nullable: true })
  clabe: string;

  @Column({ name: 'account_type', type: 'varchar', length: 20, default: 'checking' })
  accountType: 'checking' | 'savings';

  @Column({ type: 'varchar', length: 3, default: 'MXN' })
  currency: string;

  // Titular
  @Column({ name: 'beneficiary_name', type: 'varchar', length: 200, nullable: true })
  beneficiaryName: string;

  @Column({ name: 'beneficiary_tax_id', type: 'varchar', length: 20, nullable: true })
  beneficiaryTaxId: string;

  // Swift para transferencias internacionales
  @Column({ name: 'swift_code', type: 'varchar', length: 20, nullable: true })
  swiftCode: string;

  // Flags
  @Column({ name: 'is_default', type: 'boolean', default: false })
  isDefault: boolean;

  @Column({ name: 'is_verified', type: 'boolean', default: false })
  isVerified: boolean;

  @Column({ name: 'verified_at', type: 'timestamptz', nullable: true })
  verifiedAt: Date | null;

  // Notas
  @Column({ type: 'text', nullable: true })
  notes: string;

  // Metadata
  @CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
  createdAt: Date;

  @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
  updatedAt: Date;
}
