import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, ManyToOne, JoinColumn, Index } from 'typeorm';
import { PlatformAccount } from './PlatformAccount.js';

@Entity('works')
@Index(['userId', 'platform'])
@Index(['accountId', 'platformVideoId'], { unique: true })
export class Work {
  @PrimaryGeneratedColumn()
  id!: number;

  @Column({ type: 'int' })
  userId!: number;

  @Column({ type: 'int' })
  accountId!: number;

  @Column({ type: 'varchar', length: 20 })
  platform!: string;

  @Column({ name: 'platform_video_id', type: 'varchar', length: 100 })
  platformVideoId!: string;

  @Column({ type: 'varchar', length: 200, default: '' })
  title!: string;

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

  @Column({ name: 'cover_url', type: 'varchar', length: 500, default: '' })
  coverUrl!: string;

  @Column({ name: 'video_url', type: 'varchar', length: 500, nullable: true })
  videoUrl!: string | null;

  @Column({ type: 'varchar', length: 20, default: '00:00' })
  duration!: string;

  @Column({ type: 'varchar', length: 20, default: 'published' })
  status!: string;

  @Column({ name: 'publish_time', type: 'datetime', nullable: true })
  publishTime!: Date | null;

  @Column({ name: 'play_count', type: 'int', default: 0 })
  playCount!: number;

  @Column({ name: 'like_count', type: 'int', default: 0 })
  likeCount!: number;

  @Column({ name: 'comment_count', type: 'int', default: 0 })
  commentCount!: number;

  @Column({ name: 'share_count', type: 'int', default: 0 })
  shareCount!: number;

  @Column({ name: 'collect_count', type: 'int', default: 0 })
  collectCount!: number;

  @CreateDateColumn({ name: 'created_at' })
  createdAt!: Date;

  @UpdateDateColumn({ name: 'updated_at' })
  updatedAt!: Date;

  @ManyToOne(() => PlatformAccount, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'accountId' })
  account?: PlatformAccount;
}
