import {
  Column,
  CreateDateColumn,
  Entity,
  Index,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';

@Entity('friendships')
@Index(['user_low_id', 'user_high_id'], { unique: true })
export class Friendship {
  @PrimaryGeneratedColumn({ type: 'bigint' })
  id: bigint;

  @Column({ type: 'bigint' })
  user_low_id: bigint;

  @Column({ type: 'bigint' })
  user_high_id: bigint;

  @CreateDateColumn({ type: 'datetime' })
  created_at: Date;
}

export enum FriendRequestStatus {
  PENDING = 'pending',
  ACCEPTED = 'accepted',
  REJECTED = 'rejected',
  CANCELLED = 'cancelled',
}

@Entity('friend_requests')
@Index(['requester_id', 'recipient_id', 'status'])
export class FriendRequest {
  @PrimaryGeneratedColumn({ type: 'bigint' })
  id: bigint;

  @Column({ type: 'bigint' })
  requester_id: bigint;

  @Column({ type: 'bigint' })
  recipient_id: bigint;

  @Column({ type: 'varchar', length: 16, default: FriendRequestStatus.PENDING })
  status: FriendRequestStatus;

  @CreateDateColumn({ type: 'datetime' })
  created_at: Date;

  @Column({ type: 'datetime' })
  expires_at: Date;

  @Column({ type: 'datetime', nullable: true })
  responded_at?: Date | null;
}

@Entity('user_blocks')
@Index(['user_id', 'blocked_user_id'], { unique: true })
export class UserBlock {
  @PrimaryGeneratedColumn({ type: 'bigint' })
  id: bigint;

  @Column({ type: 'bigint' })
  user_id: bigint;

  @Column({ type: 'bigint' })
  blocked_user_id: bigint;

  @CreateDateColumn({ type: 'datetime' })
  created_at: Date;
}

@Entity('direct_messages')
@Index(['sender_id', 'recipient_id', 'created_at'])
@Index(['recipient_id', 'read_at'])
export class DirectMessage {
  @PrimaryGeneratedColumn({ type: 'bigint' })
  id: bigint;

  @Column({ type: 'bigint' })
  sender_id: bigint;

  @Column({ type: 'bigint' })
  recipient_id: bigint;

  @Column({ type: 'varchar', length: 1000 })
  content: string;

  @CreateDateColumn({ type: 'datetime' })
  created_at: Date;

  @Column({ type: 'datetime' })
  expires_at: Date;

  @Column({ type: 'datetime', nullable: true })
  read_at?: Date | null;
}

@Entity('user_reports')
@Index(['reporter_id', 'created_at'])
export class UserReport {
  @PrimaryGeneratedColumn({ type: 'bigint' })
  id: bigint;

  @Column({ type: 'bigint' })
  reporter_id: bigint;

  @Column({ type: 'bigint' })
  reported_user_id: bigint;

  @Column({ type: 'varchar', length: 32 })
  reason: string;

  @Column({ type: 'varchar', length: 500, nullable: true })
  note?: string | null;

  @Column({ type: 'bigint', nullable: true })
  message_id?: bigint | null;

  @Column({ type: 'varchar', length: 24, default: 'received' })
  status: string;

  @CreateDateColumn({ type: 'datetime' })
  created_at: Date;
}

@Entity('player_travel_unlocks')
@Index(['user_id', 'destination_id'], { unique: true })
export class PlayerTravelUnlock {
  @PrimaryGeneratedColumn({ type: 'bigint' })
  id: bigint;

  @Column({ type: 'bigint' })
  user_id: bigint;

  @Column({ type: 'varchar', length: 80 })
  destination_id: string;

  @CreateDateColumn({ type: 'datetime' })
  discovered_at: Date;
}

@Entity('social_notifications')
@Index(['user_id', 'read_at', 'created_at'])
export class SocialNotification {
  @PrimaryGeneratedColumn({ type: 'bigint' })
  id: bigint;

  @Column({ type: 'bigint' })
  user_id: bigint;

  @Column({ type: 'varchar', length: 48 })
  category: string;

  @Column({ type: 'varchar', length: 100 })
  title: string;

  @Column({ type: 'varchar', length: 500 })
  content: string;

  @Column({ type: 'json', nullable: true })
  action_metadata?: Record<string, unknown> | null;

  @Column({ type: 'datetime', nullable: true })
  read_at?: Date | null;

  @CreateDateColumn({ type: 'datetime' })
  created_at: Date;

  @Column({ type: 'datetime' })
  expires_at: Date;

  @UpdateDateColumn({ type: 'datetime' })
  updated_at: Date;
}
