<?php

namespace App\Models;

use App\Enums\ServicePackageStatusEnum;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * @property int $id
 * @property int $client_id
 * @property ServicePackageStatusEnum $status
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @property-read \App\Models\Client $client
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ServicePackageItem> $items
 * @property-read int|null $items_count
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Schedule> $schedules
 * @property-read int|null $schedules_count
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServicePackage newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServicePackage newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServicePackage onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServicePackage query()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServicePackage whereClientId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServicePackage whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServicePackage whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServicePackage whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServicePackage whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServicePackage whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServicePackage withTrashed(bool $withTrashed = true)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServicePackage withoutTrashed()
 * @mixin \Eloquent
 */
class ServicePackage extends Model
{
    use HasFactory, SoftDeletes;

    protected $table = 'service_packages';

    protected $fillable = [
        'client_id',
        'provider_id',
        'status',
    ];

    protected $casts = [
        'status'     => ServicePackageStatusEnum::class,
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
        'deleted_at' => 'datetime',
    ];

    public function client()
    {
        return $this->belongsTo(Client::class);
    }

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

    public function payments()
    {
        return $this->hasMany(Payment::class);
    }

    public function items()
    {
        return $this->hasMany(ServicePackageItem::class);
    }

    public function schedules()
    {
        return $this->belongsToMany(Schedule::class, 'service_package_items')
            ->withTimestamps();
    }
}
