<?php

namespace app\model;

use DateTimeInterface;
use support\Model;

class ClientMessage extends Model
{
    protected $table = 'client_message';

    protected $primaryKey = 'client_message_id';

    protected $dateFormat = 'U';

    const CREATED_AT = 'client_message_addtimes';

    const UPDATED_AT = null;

    public function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    public function member()
    {
        return $this->hasOne(Member::class, 'member_id', 'join_client_message_recv_member_id')
            ->select('member_id', 'member_mobile');
    }

    public function cert()
    {
        return $this->hasOne(MemberCert::class, 'join_cert_member_id', 'join_client_message_recv_member_id')
            ->select('join_cert_member_id', 'member_cert_name');
    }

    public function info()
    {
        return $this->hasOne(MemberInfo::class, 'join_info_member_id', 'join_client_message_recv_member_id')
            ->select('join_info_member_id', 'member_info_nickname');
    }
}