import { Entity, Column, PrimaryGeneratedColumn, OneToOne, JoinColumn, OneToMany, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, ManyToMany, JoinTable, ManyToOne, Unique, Index } from 'typeorm';
import { v4 as uuidv4 } from 'uuid';
import { Exclude, Expose } from 'class-transformer';
import { InfluencerCategory } from './influencer-caregories.entity';
import { CategoryTranslation } from './category-translations.entity';
import { CountryRecommendedCategory } from './country-recommended-categories.entity';

@Entity({ name: 'categories' })
export class Categories {

  @PrimaryGeneratedColumn('uuid')
  id: string;

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

  @Column({ type: 'boolean', default: false })
  is_recommended: boolean;

  @Column({ type: 'boolean', default: false })
  is_hidden: boolean;

  @Column({ type: 'text', nullable: true })
  image: string;

  @Index()
  @Column({ default: "" })
  title: string;

  @Index()
  @Column({ default: "" })
  slug: string;

  @Column({ type: 'text', nullable: true })
  description: string;

  @Column({ type: 'text', nullable: true })
  tags: 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(() => InfluencerCategory, (category) => category.category)
  influencerCategories: InfluencerCategory[];

  @OneToMany(() => CategoryTranslation, (translation) => translation.category)
  translations: CategoryTranslation[];

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

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