import { Entity, Column, PrimaryGeneratedColumn, OneToOne, JoinColumn, OneToMany, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, ManyToMany, JoinTable, ManyToOne, Unique } from 'typeorm';
import { v4 as uuidv4 } from 'uuid';
import { Exclude, Expose } from 'class-transformer';
import { CountryPaymentMethod } from './country-payment-method.entity';
import { CountryRecommendedCategory } from './country-recommended-categories.entity';

@Entity({ name: 'countries' })
export class Countries {

  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ default: "" })
  two_digit_code: string;

  @Column({ default: "" })
  three_digit_code: string;

  @Column({ default: "" })
  country_name: string;

  @Column({ type: 'int', default: 50 })
  order_by: number;

  @Column({ type: 'varchar', nullable: true })
  country_code: string;

  @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.country)
  countryPaymentMethods: CountryPaymentMethod[];

  @OneToMany(() => CountryRecommendedCategory, (countryRecommendedCategory) => countryRecommendedCategory.country)
  countryRecommendedCategories: CountryRecommendedCategory[];

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