package es.uv.dagarcos.master.domain;

import jakarta.persistence.*;
import java.time.Instant;

@Entity
@Table(
    name = "players_global",
    indexes = {
        @Index(name = "idx_player_external_id", columnList = "externalPlayerId", unique = true)
    }
)
public class PlayerGlobal {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false, updatable = false)
    private String externalPlayerId;

    private Instant firstSeenAt;

    private Instant lastSeenAt;

    private long globalScore;

    protected PlayerGlobal() {}

    public PlayerGlobal(String externalPlayerId) {
        this.externalPlayerId = externalPlayerId;
        this.firstSeenAt = Instant.now();
        this.lastSeenAt = this.firstSeenAt;
        this.globalScore = 0;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getExternalPlayerId() {
        return externalPlayerId;
    }

    public void setExternalPlayerId(String externalPlayerId) {
        this.externalPlayerId = externalPlayerId;
    }

    public Instant getFirstSeenAt() {
        return firstSeenAt;
    }

    public void setFirstSeenAt(Instant firstSeenAt) {
        this.firstSeenAt = firstSeenAt;
    }

    public Instant getLastSeenAt() {
        return lastSeenAt;
    }

    public void setLastSeenAt(Instant lastSeenAt) {
        this.lastSeenAt = lastSeenAt;
    }

    public long getGlobalScore() {
        return globalScore;
    }

    public void setGlobalScore(long globalScore) {
        this.globalScore = globalScore;
    }

   
    public void touch() {
        this.lastSeenAt = Instant.now();
    }

}
