import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { Article } from '../entities';

export type SharePlatform =
  | 'facebook'
  | 'twitter'
  | 'instagram'
  | 'tiktok'
  | 'telegram'
  | 'link';

@Entity('share_events')
export class ShareEvent {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column()
  articleId: string;

  @Column({ type: 'text' })
  platform: SharePlatform;

  @Column({ nullable: true })
  userId: string;

  @Column({ nullable: true })
  userAgent: string;

  @Column({ nullable: true })
  ipAddress: string;

  @CreateDateColumn()
  createdAt: Date;

  @ManyToOne(() => Article, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'articleId' })
  article: Article;
}

export interface ShareStats {
  articleId: string;
  articleTitle: string;
  facebookShares: number;
  twitterShares: number;
  instagramShares: number;
  tiktokShares: number;
  telegramShares: number;
  linkShares: number;
  totalShares: number;
  views: number;
  shareRate: number;
}
