package com.remy.user.entity;

import com.remy.common.entity.BaseEntity;
import com.remy.common.enumeration.GenderEnum;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Singular;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.ColumnTransformer;

import javax.persistence.*;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Entity
@SuperBuilder
@NoArgsConstructor
@Data
@Table(name = "t_user")
public class User extends BaseEntity {

    @Column(name = "username", unique = true)
    private String username;

    @Column(name = "password")
    @ColumnTransformer(
            read = "AES_DECRYPT(UNHEX(password), 'my_pass')",
            write = "HEX(AES_ENCRYPT(?, 'my_pass'))"
    )
    private String password;

    @Column(name = "nickname")
    private String nickname;

    @Column(name = "img")
    private String img;

    @Column(name = "gender")
    @Enumerated(EnumType.STRING)
    private GenderEnum gender;

    @Column(name = "age")
    private Integer age;

    @Column(name = "birthday")
    private LocalDate birthday;

    @Column(name = "level")
    @Builder.Default
    private Integer level = 1;

    @ElementCollection
    @Column(name = "addresses")
    @Singular
    private List<String> addresses;

}
