package com.alterdekim.hearthhack.entity;

import com.alterdekim.hearthhack.dto.BoosterDTO;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "boosters")
@SqlResultSetMapping(
        name = "boosterEntityMapping",
        classes = {
                @ConstructorResult(
                        targetClass = BoosterDTO.class,
                        columns = {
                                @ColumnResult(name = "type", type = Integer.class),
                                @ColumnResult(name = "count", type = Integer.class)
                        }
                )
        }
)
@NamedNativeQuery(
        name = "Booster.findBoostersByUserId",
        query = "SELECT b.type as type, COUNT(b.id) as count FROM boosters b WHERE b.user_id = :userId GROUP BY b.type",
        resultSetMapping = "boosterEntityMapping"
)
public class Booster {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false)
    private Integer type;

    @Column(nullable = false)
    private Long userId;

    public Booster(Long userId, Integer type) {
        this.type = type;
        this.userId = userId;
    }
}
