import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
  DeleteDateColumn,
  OneToMany,
} from 'typeorm';
import { v4 as uuidv4 } from 'uuid';
import { Exclude } from 'class-transformer';
import { CountryPaymentMethod } from './country-payment-method.entity';
import { InfluencerPaymentMethod } from './influencer-payment-method.entity';

@Entity({ name: 'payment_methods' })
export class PaymentMethod {
  @PrimaryGeneratedColumn('uuid')
  id: string;

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

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

  @Column({ type: 'jsonb', nullable: true })
  json_text: Record<string, any> | null;

  @Exclude()
  @CreateDateColumn({
    type: 'timestamp',
    precision: 0,
    default: () => 'CURRENT_TIMESTAMP',
  })
  created_at: Date;

  @Exclude()
  @UpdateDateColumn({
    type: 'timestamp',
    precision: 0,
    default: () => 'CURRENT_TIMESTAMP',
    onUpdate: 'CURRENT_TIMESTAMP',
  })
  updated_at: Date;

  @Exclude()
  @DeleteDateColumn({ type: 'timestamp', nullable: true, precision: 0 })
  deleted_at: Date;

  @OneToMany(() => CountryPaymentMethod, (countryPaymentMethod) => countryPaymentMethod.payment_method)
  countryPaymentMethods: CountryPaymentMethod[];

  @OneToMany(() => InfluencerPaymentMethod, (influencerPaymentMethod) => influencerPaymentMethod.payment_method)
  influencerPaymentMethods: InfluencerPaymentMethod[];

  setDefaults() {
    this.id = this.id || uuidv4();
  }
}
