import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn,
  Unique,
} from 'typeorm';
import { CommunityGoal } from './community-goal.entity';
import { Character } from '../character/entities/character.entity';

@Entity('community_contributions')
@Unique(['communityGoalId', 'characterId'])
export class CommunityContribution {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ name: 'community_goal_id' })
  communityGoalId: string;

  @ManyToOne(() => CommunityGoal)
  @JoinColumn({ name: 'community_goal_id' })
  communityGoal: CommunityGoal;

  @Column({ name: 'character_id' })
  characterId: string;

  @ManyToOne(() => Character)
  @JoinColumn({ name: 'character_id' })
  character: Character;

  @Column({ name: 'contribution_value', type: 'bigint', default: 0 })
  contributionValue: number;
}
