import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { Deposit } from './deposit.entity';

@Entity('deposit_installments')
export class DepositInstallment {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ name: 'deposit_id' })
  depositId: number;

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

  @Column({ name: 'due_date', type: 'date' })
  dueDate: string;

  @Column({ name: 'paid_date', type: 'date', nullable: true })
  paidDate: string;

  @Column({ type: 'varchar', length: 20, default: 'pending' })
  status: string; // pending | paid

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

  @ManyToOne(() => Deposit, (d) => d.installments, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'deposit_id' })
  deposit: Deposit;

}
