import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  Index,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { UserEntity } from '../../user/entities/user.entity';

@Entity('user_sessions')
export class UserSessionEntity {
  @PrimaryGeneratedColumn({ type: 'bigint' })
  id: number;

  @Column({ name: 'user_id', type: 'bigint' })
  userId: number;

  @ManyToOne(() => UserEntity)
  @JoinColumn({ name: 'user_id' })
  user: UserEntity;

  @Index()
  @Column({ name: 'session_token', type: 'varchar', length: 255 })
  sessionToken: string;

  @Column({ name: 'device_id', type: 'varchar', length: 100, nullable: true })
  deviceId: string;

  @Column({
    name: 'device_type',
    type: 'enum',
    enum: ['android', 'ios', 'tablet', 'web', 'mobile', 'desktop'],
    default: 'android',
  })
  deviceType: 'android' | 'ios' | 'tablet' | 'web' | 'mobile' | 'desktop';

  @Column({
    name: 'firebase_token',
    type: 'varchar',
    length: 255,
    nullable: true,
  })
  firebaseToken: string;

  @Column({ name: 'is_active', type: 'tinyint', default: 1 })
  isActive: number;

  @CreateDateColumn({ name: 'created_at', type: 'timestamp' })
  createdAt: Date;

  @Column({ name: 'expires_at', type: 'timestamp', nullable: true })
  expiresAt: Date;
}
