<?php

namespace App\Models\Crm;

use App\Models\User;
use App\Traits\BelongsToStore;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class Customer extends Model
{
    use BelongsToStore, SoftDeletes;

    protected $fillable = [
        'store_id', 'lead_id', 'name', 'phone', 'id_card', 'wechat',
        'birthday', 'expected_date', 'actual_date', 'baby_count',
        'tags', 'status', 'owner_id', 'remark',
    ];

    protected function casts(): array
    {
        return [
            'birthday' => 'date',
            'expected_date' => 'date',
            'actual_date' => 'date',
            'baby_count' => 'integer',
            'tags' => 'array',
            'status' => 'integer',
        ];
    }

    public function lead(): BelongsTo
    {
        return $this->belongsTo(Lead::class);
    }

    public function owner(): BelongsTo
    {
        return $this->belongsTo(User::class, 'owner_id');
    }

    public function families(): HasMany
    {
        return $this->hasMany(CustomerFamily::class);
    }

    public function contracts(): HasMany
    {
        return $this->hasMany(Contract::class);
    }

    public function questionnaireAnswers(): HasMany
    {
        return $this->hasMany(QuestionnaireAnswer::class);
    }

    public function complaints(): HasMany
    {
        return $this->hasMany(Complaint::class);
    }
}
