<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class Plant extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'code',
        'company_id',
        'name',
        'address',
    ];

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

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

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

    public function getLineNames()
    {
        return $this->hasMany(Line::class, 'plant_id', 'id');
    }

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

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

    public function invoiceValidations()
    {
        return $this->hasMany(InvoiceValidation::class, 'sticker_master_id');
    }

    public function qualityValidations()
    {
        return $this->hasMany(QualityValidation::class, 'sticker_master_id');
    }

    public function testingPanelReadings()
    {
        return $this->hasMany(TestingPanelReading::class);
    }

    public function guardNames()
    {
        return $this->hasMany(GuardName::class, 'plant_id', 'id');
    }

    public function checkPointNames()
    {
        return $this->hasMany(CheckPointName::class, 'plant_id', 'id');
    }

    public function checkPointTimes()
    {
        return $this->hasMany(CheckPointTime::class, 'plant_id', 'id');
    }

    public function guardPatrolEntries()
    {
        return $this->hasMany(GuardPatrolEntry::class, 'plant_id', 'id');
    }

    public function workGroupMasters()
    {
        return $this->hasMany(WorkGroupMaster::class, 'plant_id', 'id');
    }

    public function equipmentMasters()
    {
        return $this->hasMany(EquipmentMaster::class, 'plant_id', 'id');
    }

    // public function rejectReasons()
    // {
    //     return $this->hasMany(RejectReason::class, 'plant_id', 'id');
    // }

    public function users()
    {
        return $this->hasMany(User::class, 'plant_id', 'id');
    }

    public function itemCharacteristics()
    {
        return $this->hasMany(ItemCharacteristic::class, 'plant_id', 'id');
    }
}
