<?php

namespace App\Models;

use App\Classes\ValueObjects\Constants\SegmentConstants;
use App\Models\AbstractModel as Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;


/**
 * Class ServiceType
 * @package App\Models
 * @version February 16, 2021, 9:04 pm
 *
 * @property string $name
 */
class ServiceType extends AbstractModel
{

    use SoftDeletes;


    protected $table = 'service_types';



    public $fillable = [
        'name'
    ];

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'name' => 'string',
            'deleted_at' => 'datetime',
        ];
    }

    /**
     * Validation rules
     *
     * @var array<string, string>
     */
    public static $rules = [
        'name' => 'required'
    ];

    /**
     * @return HasMany
     */
    public function rates(): HasMany
    {
        return $this->hasMany(CurrencyRate::class, 'service_id');
    }

    /**
     * @return HasMany
     */
    public function constants(): HasMany
    {
        return $this->hasMany(SegmentConstant::class, 'detail->id')
            ->whereIn('reference', [SegmentConstants::SERVICE_TYPE, SegmentConstants::CUSTOM_SERVICE_TYPE]);
    }

}
