<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Schedule extends Model
{
    use HasFactory, SoftDeletes;

    protected $fillable = [
        'client_id',
        'provider_id',
        'address_id',
        'date',
        'period_type',
        'schedule_type',
        'start_time',
        'end_time',
        'status',
        'total_amount',
        'code',
        'code_verified',
        'offers_meal',
        'cancel_text',
        'cancelled_by',
    ];

    protected $casts = [
        'date' => 'date',
        'code_verified' => 'boolean',
        'total_amount' => 'decimal:2',
        'offers_meal' => 'boolean',
    ];

    public function client()
    {
        return $this->belongsTo(Client::class)->select('id', 'user_id','average_rating');
    }

    public function provider()
    {
        return $this->belongsTo(Provider::class);
    }

    public function address()
    {
        return $this->belongsTo(Address::class, 'address_id')->select('id','district');
    }

    public function customSchedule()
    {
        return $this->hasOne(CustomSchedule::class)->select('id', 'service_type_id', 'min_price', 'max_price', 'schedule_id');
    }

    public function proposals()
    {
        return $this->hasMany(ScheduleProposal::class);
    }

    public function refuses()
    {
        return $this->hasMany(ScheduleRefuse::class);
    }

    public function reviews()
    {
        return $this->hasMany(Review::class);
    }
}
