package gaf3.core.services.user.entity

import com.fasterxml.jackson.annotation.JsonIgnore
import gaf3.core.jpa.GafTimestamp
import gaf3.core.jpa.annotation.WithStringMatcher
import org.springframework.data.domain.ExampleMatcher
import javax.persistence.*
import javax.validation.constraints.NotEmpty

@Entity
@Table(name = "GAF_USER_INFO")
@WithStringMatcher
class GafUserInfo @JvmOverloads constructor(userId: String? = null) : GafTimestamp() {
    @Id
    @Column(name = "USER_ID", length = 48)
    var userId: String? = null

    @WithStringMatcher(ExampleMatcher.StringMatcher.STARTING)
    @NotEmpty
    @Column(name = "NAME", length = 48)
    var name: String? = null

    @Column(name = "TITLE")
    var title: String? = null

    @Column(name = "STATUS", length = 48)
    var status: String? = null

    @Column(name = "GENDER", length = 48)
    var gender: String? = null

    @Column(name = "MOBILE", length = 48)
    var mobile: String? = null

    @Column(name = "EMAIL")
    var email: String? = null

    @Column(name = "REMARK")
    var remark: String? = null

    @Column(name = "ORIGIN", length = 48)
    var origin: String? = null

    @JsonIgnore
    @OneToOne(cascade = [CascadeType.MERGE, CascadeType.REFRESH], fetch = FetchType.LAZY)
    @PrimaryKeyJoinColumn(name = "USER_ID")
    var acct: GafUserAccount? = null

//    @OneToOne(cascade = [CascadeType.MERGE, CascadeType.REFRESH], fetch = FetchType.EAGER)
//    @JoinTable(name = "GAF_USER_ACCT", joinColumns = [JoinColumn(name = "USER_ID", insertable = false, updatable = false)], inverseJoinColumns = [JoinColumn(name = "USER_ID", insertable = false, updatable = false)])
//    var acct: GafUserAccount? = null
//
//
    init {
        this.userId = userId
    }
}