package cn.quantgroup.xyqb.entity;

import cn.quantgroup.user.enums.BizType;
import cn.quantgroup.user.enums.Relation;
import cn.quantgroup.xyqb.model.Tuple;
import cn.quantgroup.xyqb.util.ValidationUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;

/**
 * Created by 11 on 2016/12/30.
 */
@Data
@Entity
@Table(name = "contact")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Contact extends BaseEntity implements Serializable {
    private static final long serialVersionUID = -1L;

    @Column(name = "user_id")
    private Long userId;
    @Column(name = "name")
    private String name;
    @Column(name = "phone_no")
    private String phoneNo;
    @Column(name = "biz_type")
    private BizType bizType = BizType.CASH;
    @Column(name = "relation")
    private Relation relation;

    /**
     * 数据合法性校验
     *
     * @return
     */
    public boolean valid() {
        return (ValidationUtil.validatePhoneNo(this.phoneNo) && ValidationUtil.validateChinese(this.name));
    }

    public Tuple<String, Boolean> validAndResult() {
        boolean phoneValidRes = ValidationUtil.validatePhoneNo(this.phoneNo);
        if (!phoneValidRes) {
            return new Tuple<>("手机号错误", false);
        }
        boolean nameValid = ValidationUtil.validateChinese(this.name);
        if (!nameValid) {
            return new Tuple<>("姓名错误", false);
        }
        return new Tuple<>("", true);
    }

}
