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 { Users } from './users.entity';
import { CountryListInstance } from 'twilio/lib/rest/pricing/v2/voice/country';
import { SocialMedias } from './social-medias.entity';
import { YoutubeChannels } from './youtube-channel.entity';
import { FacebookPages } from './facebook-pages.entity';
import { InstagramProfiles } from './instagram-profile.entity';



@Entity({ name: 'instagram_medias' })
export class InstagramMedias {

  @PrimaryGeneratedColumn('uuid')
  id: string;

  @ManyToOne(() => Users, user => user.id, { nullable: true })
  @JoinColumn({ name: "users" })
  users: Users;

  @ManyToOne(() => SocialMedias, (socialMedia) => socialMedia.id)
  @JoinColumn({ name: "socialMedia" })
  socialMedia: SocialMedias;

  @ManyToOne(() => InstagramProfiles, (instagramProfiles) => instagramProfiles.id)
  @JoinColumn({ name: "instagramProfiles" })
  instagramProfiles: InstagramProfiles;

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

  @Index()
  @Column({ type: 'text', default: "" })
  username: string;

  @Column({ type: 'text', default: "" })
  thumbnail_url: string;

  @Column({ type: 'text', default: "" })
  media_url: string;

  @Column({ type: 'text', default: "" })
  permalink: string;

  @Column({ type: 'text', default: "" })
  instagram_media_id: string;

  @Column({ type: 'text', default: "" })
  is_comment_enabled: string;

  @Column({ type: 'text', default: "" })
  media_product_type: string;

  @Column({ type: 'text', default: "" })
  media_type: string;

  @Column({ type: 'text', default: "" })
  shortcode: string;

  @Column({ type: 'text', default: "" })
  instagram_timestamp: string;

  @Column({ type: 'bigint', default: 0 })
  comments_count: string;

  @Column({ type: 'bigint', default: 0 })
  like_count: string;

  @Column({ type: 'bigint', default: 0 })
  reel_views_count: 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;

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