package mx.gob.slp.baseadminweb.domain.model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

import java.time.Instant;

@Entity
@Table(name = "pass_codes")
public class PassCode {

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

    @Column(nullable = false, length = 120)
    private String name;

    @Column(nullable = false, unique = true, length = 16, updatable = false)
    private String code;

    @Column(nullable = false, updatable = false)
    private Instant createdAt;

    @Enumerated(EnumType.STRING)
    @Column(nullable = false, length = 20)
    private PassCodeStatus status;

    @Column(nullable = false)
    private boolean scanned;

    private Instant scannedAt;

    protected PassCode() {
    }

    public PassCode(String name, String code, Instant createdAt) {
        this.name = name;
        this.code = code;
        this.createdAt = createdAt;
        this.status = PassCodeStatus.ACTIVO;
        this.scanned = false;
    }

    public Long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getCode() {
        return code;
    }

    public Instant getCreatedAt() {
        return createdAt;
    }

    public PassCodeStatus getStatus() {
        return status;
    }

    public boolean isScanned() {
        return scanned;
    }

    public Instant getScannedAt() {
        return scannedAt;
    }

    public void markAsUsed(Instant scannedAt) {
        this.status = PassCodeStatus.UTILIZADO;
        this.scanned = true;
        this.scannedAt = scannedAt;
    }
}