<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class Service extends BaseModel
{
    use HasFactory, Notifiable;
    protected $table = 'services';
    protected $fillable = ['id','name', 'notes', 'status', 'created_by', 'created_at', 'updated_by', 'updated_by',
        'updated_at'];

    function processvalues($formvalues, $userid, $now){
            $status = [];
        $id = !is_null($formvalues['id']) ? decrypt($formvalues['id']) : null;
        $postModel = new Service();
        $duplicate = $postModel->findDuplicate(Nationality::class, 'name', $formvalues['name'], $id);
        $formData = [
            'id' => $id,
            'name' => $formvalues['name'],
            'notes' => $formvalues['name'],
            'status' => $formvalues['status'] ?? '0'
        ];

        if(!$duplicate){
            $result = $postModel->processPost(Nationality::class, $formData, $userid, $now);
            if ($result) {
                $status['success_message'] = "Post saved or updated successfully.";
            } else {
                $status['error_message'] = "Failed to save or update the post.";
            }
        }else{
            $status['error_message'] = "You have provided an Entry that is already exists";
        }

        return $status;
    }


}
