<?php

namespace App;

use Illuminate\Database\Eloquent\Model;


class Scale extends Model
{
  private $generic_condition;

   public function __construct()
    {
           
       $this->setCondition(['is_recycle' => '0']);
    }

    public function setCondition($condition = [])
    {
        $this->generic_condition = $condition;
    }

    public function getCondition()
    {
        return $this->generic_condition;
    }

    public function getScaleList()
    {
        return Scale::where($this->getCondition())->orderBy('id','asc')->get();
    }

    public function storeScale($object)
    {
        return \DB::transaction(function () use ($object)  {

            

          $scale                = new Scale;
          $scale->code          = $object['code'];
          $scale->title         = $object['title'];

          $scale->save();


            return with($scale);
          

        });
    }

       public function updateScale($object,$scale_id)
    {

       return \DB::transaction(function () use ($object, $scale_id) {

            $scale = Scale::find($scale_id);

            if(isset($scale->id))
            {
       
             $scale->code          = $object['code'];
             $scale->title         = $object['title'];

        

             $scale->update();

                return with($scale);
                
                return 1;
            }
            
            return 0;
        });
    }
}
