<?php

namespace App\Traits;

use App\Models\User;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Http\Response;

trait AbstractModel
{

    protected static function booted(): void
    {
        static::creating(function (self $model){
            $model->created_by = tenant_user()->id;
        });

        static::updating(function (self $model){
            $model->last_updated_by = tenant_user()->id;
        });

        static::deleting(function (self $model){
            $model->deleted_by = tenant_user()->id;
        });
    }

    public function createdBy(): BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    public function lastUpdatedBy(): BelongsTo
    {
        return $this->belongsTo(User::class, 'last_updated_by');
    }

    public function deletedBy(): BelongsTo
    {
        return $this->belongsTo(User::class, 'deleted_by');
    }


    /**
     * Get the data that is not in the schema but should be appended when retrieving model
     *
     * @return array
     */
    public function appends(): array
    {
        return [];
    }

    /**
     * Get the attributes that should be hidden when the model is getting retrieved
     *
     * @return array
     */
    public function hidden(): array
    {
        return [];
    }


    /**
     * Get the system validations set for the model
     *
     * @return array
     */
    public function getSystemValidationRules(): array
    {
        return [];
    }

    /**
     * Insert data into the system default columns
     *
     * @param array $data
     * @return void
     */
    public function insertSystemData(array $data): void
    {

    }

    /**
     * Update system default columns
     *
     * @param array $data
     * @return void
     */
    public function updateSystemData(array $data): void
    {
    }

    /**
     * Attempt to delete the data
     *
     * @return Response
     */
    public function callDeleteMethod(): Response
    {
        return response()->deleted();
    }


}
