import {
  Column,
  CreateDateColumn,
  Entity,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { EntityHelper } from 'src/utils/entity-helper';
import { Team } from 'src/teams/entities/team.entity';
import { TransactionType } from 'src/transactions/entitites/transaction-type.entity';
import { RecurringTransactionIntervalEnum } from '../recurring-transaction-interval.enum';

@Entity()
export class RecurringTransaction extends EntityHelper {
  @PrimaryGeneratedColumn()
  id: number;

  @ManyToOne(() => Team, {
    eager: false,
  })
  team: Team;

  @Column({ default: '' })
  description: string;

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

  @ManyToOne(() => TransactionType, {
    eager: true,
  })
  type: TransactionType;

  @Column()
  interval: RecurringTransactionIntervalEnum;

  @Column()
  nextRunDate: string;

  @Column({ default: true })
  active: boolean;

  @CreateDateColumn()
  createdAt: Date;
}
