<?php

namespace app\common\model;

use think\Model;

class AppointmentApplication extends Model
{
    protected $updateTime = false;

    const APPOINTMENT_PERIOD_MORNING = 1;
    const APPOINTMENT_PERIOD_AFTERNOON = 2;
    const APPOINTMENT_PERIOD_NIGHT = 3;

    const STATUS_NOT_SIGN = 0;
    const STATUS_SIGN = 1;
    const STATUS_NOT_COME = 2;
    const STATUS_CANCEL = 3;

    const STATUS = [
        self::STATUS_NOT_SIGN => '未签到', //除了这个,其他都是完成的状态
        self::STATUS_SIGN => '已签到',
        self::STATUS_NOT_COME => '爽约',
        self::STATUS_CANCEL => '已取消',
    ];

    const SEX_UNKNOW = 0;
    const SEX_MAN = 1;
    const SEX_WOMAN = 2;

    const SEXS = [
        self::SEX_UNKNOW => '未知',
        self::SEX_MAN => '男',
        self::SEX_WOMAN => '女'
    ];

    const EDUCATION_LEVELS = [
        1 => "小学", 2 => "初中", 3 => "高中", 4 => "大学及以上"
    ];

    const MARRIAGE_STATUS = [
        0 => "未婚", 1 => "己婚", 2 => "离异"
    ];

    const PROBLEM_TYPES = [
        0 => "其他", 1 => "自我意识", 2 => "人际关系", 3 => "亲子关系", 4 => "情绪问题", 5 => "学习问题"
    ];

    //problem_type_text
    public function getProblemTypeTextAttr($value, $data)
    {
        return self::PROBLEM_TYPES[$data['problem_type']]??'';
    }

    //marriage_text
    public function getMarriageTextAttr($value, $data)
    {
        return self::MARRIAGE_STATUS[$data['marriage']]??'';
    }

    //education_level_text
    public function getEducationLevelTextAttr($value, $data)
    {
        return self::EDUCATION_LEVELS[$data['education_level']]??'';
    }

    //appointment_date
    public function getAppointmentDateAttr($value, $data)
    {
        if (empty($this->appointmentTicket)) {
            return '';
        } else {
            return $this->appointmentTicket->appointment_daytime;
        }
    }

    //childs_text
    public function getChildsTextAttr($value, $data)
    {
        return $data['childs_num_str'];
    }

    //sex_text
    public function getSexTextAttr($value, $data)
    {
        return self::SEXS[$data['sex']]??'';
    }

    //childs_sex1_text
    public function getChildsSex1TextAttr($value, $data)
    {
        return self::SEXS[$data['childs_sex1']]??'';
    }

    //childs_sex2_text
    public function getChildsSex2TextAttr($value, $data)
    {
        return self::SEXS[$data['childs_sex2']]??'';
    }

    //childs_sex3_text
    public function getChildsSex3TextAttr($value, $data)
    {
        return self::SEXS[$data['childs_sex3']]??'';
    }

    //finish_time
    public function getFinishTimeAttr($value, $data)
    {
        return $value ? date('Y-m-d H:i:s', $value) : '';
    }

    //status_text
    public function getStatusTextAttr($value, $data)
    {
        return self::STATUS[$data['status']]??'';
    }


    //关联地址
    public function address()
    {
        return $this->belongsTo('Address');
    }

    //关联专家
    public function specialist()
    {
        return $this->belongsTo('Specialist', 'provider_id');
    }

    //关联号源
    public function appointmentTicket()
    {
        return $this->belongsTo('AppointmentTicket');
    }

    public function ticket()
    {
        return $this->hasOne(AppointmentTicket::class,'id','appointment_ticket_id');
    }
}
