import { Entity, PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, JoinColumn, CreateDateColumn, UpdateDateColumn } from 'typeorm';
import { RouteEntity } from '@/server/modules/routes/route.entity';
import { LocationEntity } from '@/server/modules/locations/location.entity';
import { DeleteStatus, DisabledStatus } from '@/share/types';

export enum ActivityType {
  DEPARTURE = 'departure', // 去程活动
  RETURN = 'return'        // 返程活动
}

@Entity({ name: 'activities' })
export class ActivityEntity {
  @PrimaryGeneratedColumn({ unsigned: true, comment: '活动ID' })
  id!: number;

  @Column({ name: 'name', type: 'varchar', length: 255, comment: '活动名称' })
  name!: string;

  @Column({ name: 'description', type: 'text', nullable: true, comment: '活动描述' })
  description!: string | null;

  @Column({
    name: 'type',
    type: 'enum',
    enum: ActivityType,
    comment: '活动类型: departure(去程), return(返程)'
  })
  type!: ActivityType;

  @Column({ name: 'start_date', type: 'timestamp', comment: '开始日期' })
  startDate!: Date;

  @Column({ name: 'end_date', type: 'timestamp', comment: '结束日期' })
  endDate!: Date;

  @Column({ name: 'venue_location_id', type: 'int', unsigned: true, comment: '举办地点ID' })
  venueLocationId!: number;

  @ManyToOne(() => LocationEntity, { nullable: false })
  @JoinColumn({ name: 'venue_location_id', referencedColumnName: 'id' })
  venueLocation!: LocationEntity;

  @OneToMany(() => RouteEntity, (route) => route.activity)
  routes!: RouteEntity[];

  @Column({ name: 'is_disabled', type: 'int', default: DisabledStatus.ENABLED, comment: '是否禁用(0:启用,1:禁用)' })
  isDisabled!: DisabledStatus;

  @Column({ name: 'is_deleted', type: 'int', default: DeleteStatus.NOT_DELETED, comment: '是否删除(0:未删除,1:已删除)' })
  isDeleted!: DeleteStatus;

  @Column({ name: 'created_by', type: 'int', nullable: true, comment: '创建人ID' })
  createdBy!: number | null;

  @Column({ name: 'updated_by', type: 'int', nullable: true, comment: '更新人ID' })
  updatedBy!: number | null;

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

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

  constructor(partial?: Partial<ActivityEntity>) {
    Object.assign(this, partial);
  }
}