<commit_before><?php

namespace Stevebauman\Maintenance\Models;

use Carbon\Carbon;
use Cartalyst\Sentry\Facades\Laravel\Sentry;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\SoftDeletes;
use Stevebauman\Maintenance\Http\Requests\WorkOrder\ReportRequest;
use Stevebauman\Maintenance\Viewers\WorkOrder\WorkOrderViewer;
use Stevebauman\Maintenance\Traits\Relationships\HasCategoryTrait;
use Stevebauman\Maintenance\Traits\Relationships\HasNotesTrait;
use Stevebauman\Maintenance\Traits\Relationships\HasLocationTrait;
use Stevebauman\Maintenance\Traits\Relationships\HasUserTrait;
use Stevebauman\Maintenance\Traits\Relationships\HasEventsTrait;

class WorkOrder extends Model
{
    use SoftDeletes;
    use HasNotesTrait;
    use HasLocationTrait;
    use HasUserTrait;
    use HasEventsTrait;
    use HasCategoryTrait;

    /**
     * The work orders table.
     *
     * @var string
     */
    protected $table = 'work_orders';

    /**
     * The work orders viewer.
     *
     * @var string
     */
    protected $viewer = WorkOrderViewer::class;

    /**
     * The work orders fillable attributes.
     *
     * @var array
     */
    protected $fillable = [
        'user_id',
        'location_id',
        'category_id',
        'request_id',
        'status_id',
        'priority_id',
        'subject',
        'description',
        'started_at',
        'completed_at',
    ];

    /**
     * The columns to keep revisions of.
     *
     * @var array
     */
    protected $revisionColumns = [
        'location_id',
        'category_id',
        'status_id',
        'priority_id',
        'subject',
        'description',
        'started_at',
        'completed_at',
    ];

    /**
     * The work orders revisionable formatted field names.
     *
     * @var array
     */
    protected $revisionColumnsFormatted = [
        'location_id' => 'Location',
        'category_id' => 'Work Order Category',
        'status_id' => 'Status',
        'priority_id' => 'Priority',
        'subject' => 'Subject',
        'description' => 'Description',
        'started_at' => 'Started At',
        'completed_at' => 'Completed At',
    ];

    /**
     * The revision column means attributes.
     *
     * @var array
     */
    protected $revisionColumnsMean = [
        'location_id' => 'revised_location',
        'category_id' => 'revised_category',
    ];

    /**
     * The belongsTo work request relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function request()
    {
        return $this->belongsTo(WorkRequest::class, 'request_id');
    }

    /**
     * The belongsToMany customer updates relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function updates()
    {
        return $this->belongsToMany(Update::class, 'work_order_updates', 'work_order_id', 'update_id');
    }

    /**
     * The hasOne status relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function status()
    {
        return $this->hasOne(Status::class, 'id', 'status_id');
    }

    /**
     * The hasOne priority relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function priority()
    {
        return $this->hasOne(Priority::class, 'id', 'priority_id');
    }

    /**
     * The belongsToMany assets relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function assets()
    {
        return $this->belongsToMany(Asset::class, 'work_order_assets', 'work_order_id', 'asset_id');
    }

    /**
     * The hasOne report relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function report()
    {
        return $this->hasOne(WorkOrderReport::class, 'work_order_id');
    }

    /**
     * The hasMany assignments relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function assignments()
    {
        return $this->hasMany(WorkOrderAssignment::class, 'work_order_id', 'id');
    }

    /**
     * The belongsToMany attachments relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function attachments()
    {
        return $this->belongsToMany(Attachment::class, 'work_order_attachments', 'work_order_id', 'attachment_id');
    }

    /**
     * The belongsToMany inventory parts relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function parts()
    {
        return $this->belongsToMany(InventoryStock::class, 'work_order_parts', 'work_order_id', 'stock_id')->withTimestamps()->withPivot('id', 'quantity');
    }

    /**
     * The hasMany sessions relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function sessions()
    {
        return $this->hasMany(WorkOrderSession::class, 'work_order_id')->latest();
    }

    /**
     * The hasMany notifiable users relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function notifiableUsers()
    {
        return $this->hasMany(WorkOrderNotification::class, 'work_order_id', 'id');
    }

    /**<commit_msg>Remove ID from parts pivot<commit_after><?php

namespace Stevebauman\Maintenance\Models;

use Carbon\Carbon;
use Cartalyst\Sentry\Facades\Laravel\Sentry;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\SoftDeletes;
use Stevebauman\Maintenance\Http\Requests\WorkOrder\ReportRequest;
use Stevebauman\Maintenance\Viewers\WorkOrder\WorkOrderViewer;
use Stevebauman\Maintenance\Traits\Relationships\HasCategoryTrait;
use Stevebauman\Maintenance\Traits\Relationships\HasNotesTrait;
use Stevebauman\Maintenance\Traits\Relationships\HasLocationTrait;
use Stevebauman\Maintenance\Traits\Relationships\HasUserTrait;
use Stevebauman\Maintenance\Traits\Relationships\HasEventsTrait;

class WorkOrder extends Model
{
    use SoftDeletes;
    use HasNotesTrait;
    use HasLocationTrait;
    use HasUserTrait;
    use HasEventsTrait;
    use HasCategoryTrait;

    /**
     * The work orders table.
     *
     * @var string
     */
    protected $table = 'work_orders';

    /**
     * The work orders viewer.
     *
     * @var string
     */
    protected $viewer = WorkOrderViewer::class;

    /**
     * The work orders fillable attributes.
     *
     * @var array
     */
    protected $fillable = [
        'user_id',
        'location_id',
        'category_id',
        'request_id',
        'status_id',
        'priority_id',
        'subject',
        'description',
        'started_at',
        'completed_at',
    ];

    /**
     * The columns to keep revisions of.
     *
     * @var array
     */
    protected $revisionColumns = [
        'location_id',
        'category_id',
        'status_id',
        'priority_id',
        'subject',
        'description',
        'started_at',
        'completed_at',
    ];

    /**
     * The work orders revisionable formatted field names.
     *
     * @var array
     */
    protected $revisionColumnsFormatted = [
        'location_id' => 'Location',
        'category_id' => 'Work Order Category',
        'status_id' => 'Status',
        'priority_id' => 'Priority',
        'subject' => 'Subject',
        'description' => 'Description',
        'started_at' => 'Started At',
        'completed_at' => 'Completed At',
    ];

    /**
     * The revision column means attributes.
     *
     * @var array
     */
    protected $revisionColumnsMean = [
        'location_id' => 'revised_location',
        'category_id' => 'revised_category',
    ];

    /**
     * The belongsTo work request relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function request()
    {
        return $this->belongsTo(WorkRequest::class, 'request_id');
    }

    /**
     * The belongsToMany customer updates relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function updates()
    {
        return $this->belongsToMany(Update::class, 'work_order_updates', 'work_order_id', 'update_id');
    }

    /**
     * The hasOne status relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function status()
    {
        return $this->hasOne(Status::class, 'id', 'status_id');
    }

    /**
     * The hasOne priority relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function priority()
    {
        return $this->hasOne(Priority::class, 'id', 'priority_id');
    }

    /**
     * The belongsToMany assets relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function assets()
    {
        return $this->belongsToMany(Asset::class, 'work_order_assets', 'work_order_id', 'asset_id');
    }

    /**
     * The hasOne report relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function report()
    {
        return $this->hasOne(WorkOrderReport::class, 'work_order_id');
    }

    /**
     * The hasMany assignments relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function assignments()
    {
        return $this->hasMany(WorkOrderAssignment::class, 'work_order_id', 'id');
    }

    /**
     * The belongsToMany attachments relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function attachments()
    {
        return $this->belongsToMany(Attachment::class, 'work_order_attachments', 'work_order_id', 'attachment_id');
    }

    /**
     * The belongsToMany inventory parts relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function parts()
    {
        return $this->belongsToMany(InventoryStock::class, 'work_order_parts', 'work_order_id', 'stock_id')->withTimestamps()->withPivot('quantity');
    }

    /**
     * The hasMany sessions relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function sessions()
    {
        return $this->hasMany(WorkOrderSession::class, 'work_order_id')->latest();
    }

    /**
     * The hasMany notifiable users relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function notifiableUsers()
    {
        return $this->hasMany(WorkOrderNotification::class, 'work_order_id', 'id');
    }

    /**
{'fraction_non_alphanumeric': 0.1233868721567171, 'fraction_numerical': 0.0, 'mean_word_length': 2.527177472167649, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7024853', 'n_tokens_mistral': 3311, 'n_tokens_neox': 3289, 'n_words': 581}