package cokr.xit.ens.modules.kkotalk.domain;

import javax.persistence.*;

import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.entity.*;
import cokr.xit.ens.modules.common.domain.*;
import cokr.xit.ens.modules.common.domain.support.*;
import cokr.xit.ens.modules.kkotalk.code.*;
import lombok.*;
import lombok.experimental.*;

@Entity
@Getter
@ToString(exclude = {"sendMast"})
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "ens_snd_dtl_kko_talk", indexes = {
        @Index(name = "idx_snd_dtl_kko_talk_uk_id", columnList = "envelope_id"),
        @Index(name = "idx_snd_dtl_kko_talk_uk", columnList = "envelope_id, external_id"),
//        @Index(name = "idx_kkomd_bill_uid", columnList = "mk_bill_uid"),
})
public class SendDetailKkoTalk extends BaseEntity {

    @Id
//	@GeneratedValue(strategy=GenerationType.AUTO)
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "SendDetailKkoTalk_Generator")
    @TableGenerator(table = "ens_seq_generator", name = "SendDetailKkoTalk_Generator"
            , pkColumnName = "seq_name", pkColumnValue = "SendDetailKkoTalk_id"
            , initialValue = 0, allocationSize = 200)
    private Long sendDetailId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "send_mast_id")
    private SendMast sendMast;

    @Column(name = "title", nullable = true, length = 40)
    @Setter
    private String title;

    @Column(name = "link", nullable = true, length = 99)
    @Setter
    private String link;

    @Column(name = "hash", nullable = true, length = 99)
    @Setter
    private String hash;

    @Column(name = "read_expires_at", nullable = true)
    private String readExpiresAt;


    @Column(name = "review_expires_at", nullable = true)
    private String reviewExpiresAt;

    @Setter
    @Column(name = "guide", nullable = true)
    private String guide;

    /**
     * payload
     */
    @Column(name = "payload", nullable = true)
    private String payload;

    /**
     * <pre>
     * 알림톡 내용에 개인정보 제거 여부
     * default: false
     * </pre>
     */
    @Column(name = "use_non_personalized_noti", nullable = true)
    private Boolean useNonPersonalizedNotification = false;

    /**
     * 수신자 CI
     */
    @Column(name = "ci", nullable = true)
    private String ci;

    /**
     * <pre>
     * 수신자 전화번호
     * ci 미전송시 필수
     * </pre>
     */
    @Column(name = "phone_number", nullable = true)
    private String phoneNumber;

    /**
     * <pre>
     * 수신자 이름
     * ci 미전송시 필수
     * </pre>
     */
    @Column(name = "name", nullable = true)
    private String name;

    /**
     * <pre>
     * 수신자 생년월일 (YYYY-MM-DD 형식)
     * ci 미전송시 필수
     * </pre>
     */
    @Column(name = "birthday", nullable = true)
    private String birthday;

    /**
     * <pre>
     * 문서매핑용 식별자 - 최대 40자
     * </pre>
     */
    @Setter
    @Column(name = "external_id", nullable = true)
    private String externalId;

    @Setter
    @Column(name = "envelope_id", nullable = true)
    private String envelopeId;

    @Setter
    @Column(name = "sent_at", nullable = true)
    private String sentAt;

    @Setter
    @Column(name = "received_at", nullable = true)
    private String receivedAt;

    @Setter
    @Column(name = "read_at", nullable = true)
    private String readAt;

    @Setter
    @Column(name = "authenticated_at", nullable = true)
    private String authenticatedAt;

    @Setter
    @Column(name = "ott_verified_at", nullable = true)
    private String ottVerifiedAt;

    @Setter
    @Column(name = "is_notification_unavailable", nullable = true)
    private String isNotificationUnavailable;

    @Setter
    @Column(name = "user_notified_at", nullable = true)
    private String userNotifiedAt;

    @Setter
    @Column(name = "distribution_received_at", nullable = true)
    private String distributionReceivedAt;

    @Embedded
    @Setter
    private FieldError error;

    @JoinColumn(name = "bill_uid", referencedColumnName = "bill_uid")
    @OneToOne(fetch = FetchType.LAZY)
    private Bill bill;

    @Column(name = "mk_jid", nullable = true, length = 24)
    private String mkJid;

    @Column(name = "mk_tmplt_msg_json_data", nullable = true, length = 4000)
    private String mkTmpltMsgJsonData;

    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false, length = 30)
    @Setter
    private KkoTalkStatusCd status;

    @Column(name = "mk_bill_use_yn", nullable = true, length = 1)
    private String mkBillUseYn;
}
