import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, OneToMany } from 'typeorm';
import { v4 as uuidv4 } from 'uuid';
import { Exclude, Expose } from 'class-transformer';

export enum KeyType {
  FACEBOOK_FOLLOWERS_COUNT = 'facebook_followers_count',
  INSTAGRAM_FOLLOWERS_COUNT = 'instagram_followers_count',
  TIKTOK_FOLLOWERS_COUNT = 'tiktok_followers_count',
  YOUTUBE_SUBSCRIBER_COUNT = 'youtube_subscriber_count',
  CATEGORY_MIN = 'category_min',
  CATEGORY_MAX = 'category_max',
  INDUSTRY_MIN = 'industry_min',
  INDUSTRY_MAX = 'industry_max',
  PLATFORM_CHARGE = 'platform_charge',
  JOB_CATEGORY_SCORE = 'job_category_score',
  PLATFORM_SCORE = 'platform_score',
  GEOGRAPHY_SCORE = 'geography_score',
  CURRENCY_SCORE = 'currency_score',
  REGISTERED_INFLUENCER_SCORE = 'registered_influencer_score',
  INFLUENCER_JOB_CATEGORY_SCORE = 'influencer_job_category_score',
  INFLUENCER_PLATFORM_SCORE = 'influencer_platform_score',
  INFLUENCER_GEOGRAPHY_SCORE = 'influencer_geography_score',
  INFLUENCER_CURRENCY_SCORE = 'influencer_currency_score',
  TRENDING_FOLLOWER_COUNT = 'trending_follower_count',
  TRENDING_ENGAGEMENT_COUNT = 'trending_engagement_count',
  TRENDING_PERCENTAGE = 'trending_percentage',
  ENCRYPTION = 'encryption',
  COMET_CHAT_MESSAGE_NOTIFICATION = 'comet_chat_message_notification',
  AI_AGENT_REPORT = 'ai_agent_report',
  AI_MODEL = 'ai_model',
  AI_AGENT_REPORT_TOP_N = 'ai_agent_report_top_n',
}

export enum SettingType {
  GENERAL = 'general',
  PLATFORM = 'platform',
  RECOMMENDED_SCORE = 'recommended_score',
  INFLUENCER_RECOMMENDED_SCORE = 'influencer_recommended_score',
  TRENDING_INFLUENCER = 'trending_influencer',
  ENCRYPTION = 'encryption',
  AI_PROMPT = 'ai_prompt',
}

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

  @Column({
    type: 'enum',
    enum: KeyType,
    default: KeyType.FACEBOOK_FOLLOWERS_COUNT,
  })
  type: string;

  @Column({
    type: 'enum',
    enum: SettingType,
    default: SettingType.GENERAL,
  })
  setting_type: string;

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

  @Column({ nullable: true })
  name: 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();
  }
}
