<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Models\{Client, Ticket, User, VisitChecklist};

class Visit extends Model
{
    protected $fillable = [
        'client_id','ticket_id','technician_id','created_by',
        'visit_date','visit_time_start','visit_time_end',
        'status','purpose','notes','is_extra','extra_charge'
    ];
    protected $casts = ['visit_date'=>'date','is_extra'=>'boolean','extra_charge'=>'decimal:2'];

    public function client()     { return $this->belongsTo(Client::class); }
    public function ticket()     { return $this->belongsTo(Ticket::class); }
    public function tickets()    { return $this->belongsToMany(Ticket::class, 'ticket_visit', 'visit_id', 'ticket_id'); }
    public function technician() { return $this->belongsTo(User::class, 'technician_id'); }
    public function createdBy()  { return $this->belongsTo(User::class, 'created_by'); }
    public function checklists() { return $this->hasMany(VisitChecklist::class); }
}
