import { Column, CreateDateColumn, Entity, PrimaryColumn } from 'typeorm';

@Entity({ name: 'racing_penalties' })
export class PenaltyOrmEntity {
  @PrimaryColumn({ type: 'uuid' })
  id!: string;

  @Column({ type: 'uuid' })
  leagueId!: string;

  @Column({ type: 'text' })
  raceId!: string;

  @Column({ type: 'uuid' })
  driverId!: string;

  @Column({ type: 'text' })
  type!: string;

  @Column({ type: 'int', nullable: true })
  value!: number | null;

  @Column({ type: 'text' })
  reason!: string;

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

  @Column({ type: 'uuid' })
  issuedBy!: string;

  @Column({ type: 'text' })
  status!: string;

  @Column({ type: 'timestamptz' })
  issuedAt!: Date;

  @Column({ type: 'timestamptz', nullable: true })
  appliedAt!: Date | null;

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

@Entity({ name: 'racing_protests' })
export class ProtestOrmEntity {
  @PrimaryColumn({ type: 'uuid' })
  id!: string;

  @Column({ type: 'text' })
  raceId!: string;

  @Column({ type: 'uuid' })
  protestingDriverId!: string;

  @Column({ type: 'uuid' })
  accusedDriverId!: string;

  @Column({ type: 'jsonb' })
  incident!: unknown;

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

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

  @Column({ type: 'text' })
  status!: string;

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

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

  @Column({ type: 'timestamptz' })
  filedAt!: Date;

  @Column({ type: 'timestamptz', nullable: true })
  reviewedAt!: Date | null;

  @Column({ type: 'jsonb', nullable: true })
  defense!: unknown | null;

  @Column({ type: 'timestamptz', nullable: true })
  defenseRequestedAt!: Date | null;

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

export type OrmMoney = { amount: number; currency: string };

@Entity({ name: 'racing_league_wallets' })
export class LeagueWalletOrmEntity {
  @PrimaryColumn({ type: 'uuid' })
  id!: string;

  @Column({ type: 'uuid' })
  leagueId!: string;

  @Column({ type: 'jsonb' })
  balance!: OrmMoney;

  @Column({ type: 'text', array: true, default: () => 'ARRAY[]::text[]' })
  transactionIds!: string[];

  @CreateDateColumn({ type: 'timestamptz' })
  createdAt!: Date;
}

@Entity({ name: 'racing_transactions' })
export class TransactionOrmEntity {
  @PrimaryColumn({ type: 'uuid' })
  id!: string;

  @Column({ type: 'uuid' })
  walletId!: string;

  @Column({ type: 'text' })
  type!: string;

  @Column({ type: 'jsonb' })
  amount!: OrmMoney;

  @Column({ type: 'jsonb' })
  platformFee!: OrmMoney;

  @Column({ type: 'jsonb' })
  netAmount!: OrmMoney;

  @Column({ type: 'text' })
  status!: string;

  @CreateDateColumn({ type: 'timestamptz' })
  createdAt!: Date;

  @Column({ type: 'timestamptz', nullable: true })
  completedAt!: Date | null;

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

  @Column({ type: 'jsonb', nullable: true })
  metadata!: Record<string, unknown> | null;
}

@Entity({ name: 'racing_sponsors' })
export class SponsorOrmEntity {
  @PrimaryColumn({ type: 'uuid' })
  id!: string;

  @Column({ type: 'text' })
  name!: string;

  @Column({ type: 'text' })
  contactEmail!: string;

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

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

  @CreateDateColumn({ type: 'timestamptz' })
  createdAt!: Date;
}

export type OrmSponsorshipPricing = unknown;

@Entity({ name: 'racing_sponsorship_pricings' })
export class SponsorshipPricingOrmEntity {
  @PrimaryColumn({ type: 'text' })
  id!: string;

  @Column({ type: 'text' })
  entityType!: string;

  @Column({ type: 'text' })
  entityId!: string;

  @Column({ type: 'jsonb' })
  pricing!: OrmSponsorshipPricing;
}

@Entity({ name: 'racing_sponsorship_requests' })
export class SponsorshipRequestOrmEntity {
  @PrimaryColumn({ type: 'uuid' })
  id!: string;

  @Column({ type: 'uuid' })
  sponsorId!: string;

  @Column({ type: 'text' })
  entityType!: string;

  @Column({ type: 'text' })
  entityId!: string;

  @Column({ type: 'text' })
  tier!: string;

  @Column({ type: 'jsonb' })
  offeredAmount!: OrmMoney;

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

  @Column({ type: 'text' })
  status!: string;

  @CreateDateColumn({ type: 'timestamptz' })
  createdAt!: Date;

  @Column({ type: 'timestamptz', nullable: true })
  respondedAt!: Date | null;

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

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

@Entity({ name: 'racing_season_sponsorships' })
export class SeasonSponsorshipOrmEntity {
  @PrimaryColumn({ type: 'uuid' })
  id!: string;

  @Column({ type: 'uuid' })
  seasonId!: string;

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

  @Column({ type: 'uuid' })
  sponsorId!: string;

  @Column({ type: 'text' })
  tier!: string;

  @Column({ type: 'jsonb' })
  pricing!: OrmMoney;

  @Column({ type: 'text' })
  status!: string;

  @CreateDateColumn({ type: 'timestamptz' })
  createdAt!: Date;

  @Column({ type: 'timestamptz', nullable: true })
  activatedAt!: Date | null;

  @Column({ type: 'timestamptz', nullable: true })
  endedAt!: Date | null;

  @Column({ type: 'timestamptz', nullable: true })
  cancelledAt!: Date | null;

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

@Entity({ name: 'racing_games' })
export class GameOrmEntity {
  @PrimaryColumn({ type: 'text' })
  id!: string;

  @Column({ type: 'text' })
  name!: string;
}